Enhancement - default.command

- Implemented default.command handling.
This commit is contained in:
Paul Beckingham 2009-06-11 01:10:53 -04:00
parent d4a9a387af
commit a58aa948b8
4 changed files with 50 additions and 26 deletions

View file

@ -72,6 +72,12 @@ void Context::initialize (int argc, char** argv)
else else
args.push_back (argv[i]); args.push_back (argv[i]);
initialize ();
}
////////////////////////////////////////////////////////////////////////////////
void Context::initialize ()
{
// Load the configuration file from the home directory. If the file cannot // Load the configuration file from the home directory. If the file cannot
// be found, offer to create a sample one. // be found, offer to create a sample one.
loadCorrectConfigFile (); loadCorrectConfigFile ();
@ -95,6 +101,7 @@ void Context::initialize (int argc, char** argv)
// TODO Handle "--version, -v" right here? // TODO Handle "--version, -v" right here?
// init TDB. // init TDB.
tdb.clear ();
std::vector <std::string> all; std::vector <std::string> all;
split (all, location, ','); split (all, location, ',');
foreach (path, all) foreach (path, all)
@ -104,7 +111,6 @@ void Context::initialize (int argc, char** argv)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int Context::run () int Context::run ()
{ {
std::cout << "--- start 1.8.0 ---" << std::endl;
try try
{ {
parse (); // Parse command line. parse (); // Parse command line.
@ -133,26 +139,12 @@ int Context::run ()
std::cout << *f << std::endl; std::cout << *f << std::endl;
} }
std::cout << "--- end 1.8.0 ---" << std::endl;
return 0; return 0;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Context::dispatch () void Context::dispatch ()
{ {
/*
// If argc == 1 and there is a default.command, use it. Otherwise use
// argc/argv.
std::string defaultCommand = context.config.get ("default.command");
if (args.size () == 0 || defaultCommand != "")
{
// Stuff the command line.
args.clear ();
split (args, defaultCommand, ' ');
std::cout << "[task " << defaultCommand << "]" << std::endl;
}
*/
bool gcMod = false; // Change occurred by way of gc. bool gcMod = false; // Change occurred by way of gc.
bool cmdMod = false; // Change occurred by way of command type. bool cmdMod = false; // Change occurred by way of command type.
std::string out; std::string out;
@ -337,7 +329,7 @@ void Context::parse ()
// The '--' argument shuts off all parsing - everything is an argument. // The '--' argument shuts off all parsing - everything is an argument.
if (*arg == "--") if (*arg == "--")
{ {
std::cout << "# parse terminator '" << *arg << "'" << std::endl; std::cout << "# parse terminator '" << *arg << "'" << std::endl;
terminated = true; terminated = true;
} }
@ -347,7 +339,7 @@ std::cout << "# parse terminator '" << *arg << "'" << std::endl;
! foundSomethingAfterSequence && ! foundSomethingAfterSequence &&
sequence.valid (*arg)) sequence.valid (*arg))
{ {
std::cout << "# parse sequence '" << *arg << "'" << std::endl; std::cout << "# parse sequence '" << *arg << "'" << std::endl;
sequence.parse (*arg); sequence.parse (*arg);
foundSequence = true; foundSequence = true;
} }
@ -356,7 +348,7 @@ std::cout << "# parse sequence '" << *arg << "'" << std::endl;
else if (arg->length () > 1 && else if (arg->length () > 1 &&
(*arg)[0] == '+') (*arg)[0] == '+')
{ {
std::cout << "# parse tag addition '" << *arg << "'" << std::endl; std::cout << "# parse tag addition '" << *arg << "'" << std::endl;
if (foundSequence) if (foundSequence)
foundSomethingAfterSequence = true; foundSomethingAfterSequence = true;
@ -367,7 +359,7 @@ std::cout << "# parse tag addition '" << *arg << "'" << std::endl;
else if (arg->length () > 1 && else if (arg->length () > 1 &&
(*arg)[0] == '-') (*arg)[0] == '-')
{ {
std::cout << "# parse tag removal '" << *arg << "'" << std::endl; std::cout << "# parse tag removal '" << *arg << "'" << std::endl;
if (foundSequence) if (foundSequence)
foundSomethingAfterSequence = true; foundSomethingAfterSequence = true;
@ -380,7 +372,7 @@ std::cout << "# parse tag removal '" << *arg << "'" << std::endl;
else if (attribute.valid (*arg)) else if (attribute.valid (*arg))
{ {
std::cout << "# parse attribute '" << *arg << "'" << std::endl; std::cout << "# parse attribute '" << *arg << "'" << std::endl;
if (foundSequence) if (foundSequence)
foundSomethingAfterSequence = true; foundSomethingAfterSequence = true;
@ -394,7 +386,7 @@ std::cout << "# parse attribute '" << *arg << "'" << std::endl;
if (foundSequence) if (foundSequence)
foundSomethingAfterSequence = true; foundSomethingAfterSequence = true;
std::cout << "# parse subst '" << *arg << "'" << std::endl; std::cout << "# parse subst '" << *arg << "'" << std::endl;
subst.parse (*arg); subst.parse (*arg);
} }
@ -402,7 +394,7 @@ std::cout << "# parse subst '" << *arg << "'" << std::endl;
else if (cmd.command == "" && else if (cmd.command == "" &&
cmd.valid (*arg)) cmd.valid (*arg))
{ {
std::cout << "# parse cmd '" << *arg << "'" << std::endl; std::cout << "# parse cmd '" << *arg << "'" << std::endl;
cmd.parse (*arg); cmd.parse (*arg);
if (foundSequence) if (foundSequence)
@ -412,7 +404,7 @@ std::cout << "# parse cmd '" << *arg << "'" << std::endl;
// Anything else is just considered description. // Anything else is just considered description.
else else
{ {
std::cout << "# parse description '" << *arg << "'" << std::endl; std::cout << "# parse description '" << *arg << "'" << std::endl;
if (foundSequence) if (foundSequence)
foundSomethingAfterSequence = true; foundSomethingAfterSequence = true;
@ -425,7 +417,7 @@ std::cout << "# parse description '" << *arg << "'" << std::endl;
// terminated, therefore everything subsequently is a description. // terminated, therefore everything subsequently is a description.
else else
{ {
std::cout << "# parse post-termination description '" << *arg << "'" << std::endl; std::cout << "# parse post-termination description '" << *arg << "'" << std::endl;
if (foundSequence) if (foundSequence)
foundSomethingAfterSequence = true; foundSomethingAfterSequence = true;
@ -439,6 +431,24 @@ std::cout << "# parse post-termination description '" << *arg << "'" << std::end
task.set ("description", descCandidate); task.set ("description", descCandidate);
constructFilter (); constructFilter ();
// If no command was specified, and there were no command line arguments
// then invoke the default command.
if (cmd.command == "" && args.size () == 0)
{
std::string defaultCommand = config.get ("default.command");
if (defaultCommand != "")
{
// Stuff the command line.
args.clear ();
split (args, defaultCommand, ' ');
std::cout << "[task " << defaultCommand << "]" << std::endl;
// Reinitialize the context and recurse.
initialize ();
parse ();
}
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -44,6 +44,7 @@ public:
~Context (); // Destructor ~Context (); // Destructor
void initialize (int, char**); // all startup void initialize (int, char**); // all startup
void initialize (); // for reinitializing
int run (); // task classic int run (); // task classic
int interactive (); // task interactive (not implemented) int interactive (); // task interactive (not implemented)
void dispatch (); // command handler dispatch void dispatch (); // command handler dispatch

View file

@ -111,6 +111,18 @@ TDB2::~TDB2 ()
unlock (); unlock ();
} }
////////////////////////////////////////////////////////////////////////////////
void TDB2::clear ()
{
mLocations.clear ();
mLock = true;
if (mAllOpenAndLocked)
unlock ();
mAllOpenAndLocked = false;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TDB2::location (const std::string& path) void TDB2::location (const std::string& path)
{ {
@ -179,7 +191,7 @@ int TDB2::loadPending (std::vector <Task>& tasks, Filter& filter)
char line[T_LINE_MAX]; char line[T_LINE_MAX];
foreach (location, mLocations) foreach (location, mLocations)
{ {
std::cout << "# location.path: " << location->path << std::endl; std::cout << "# location.path: " << location->path << "" << std::endl;
line_number = 1; line_number = 1;
file = location->path + "/pending.data"; file = location->path + "/pending.data";
@ -226,7 +238,7 @@ int TDB2::loadCompleted (std::vector <Task>& tasks, Filter& filter)
char line[T_LINE_MAX]; char line[T_LINE_MAX];
foreach (location, mLocations) foreach (location, mLocations)
{ {
std::cout << "# location.path: " << location->path << std::endl; std::cout << "# location.path: " << location->path << "" << std::endl;
// TODO If the filter contains Status:x where x is not deleted or // TODO If the filter contains Status:x where x is not deleted or
// completed, then this can be skipped. // completed, then this can be skipped.

View file

@ -45,6 +45,7 @@ public:
TDB2& operator= (const TDB2&); // Assignment operator TDB2& operator= (const TDB2&); // Assignment operator
~TDB2 (); // Destructor ~TDB2 (); // Destructor
void clear ();
void location (const std::string&); void location (const std::string&);
void lock (bool lockFile = true); void lock (bool lockFile = true);