mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-29 17:07:19 +02:00
Commands
- Implemented stubbed Context::initialize2. - Implemented combined command line. - Migrated some code from Context::initialize to ::initialize2. - Integrated ::initialize2 into the startup sequence. - Implemented Context::dispatch2. - Integrated ::dispatch2 into the run sequence. - Implemented Context::updateXtermTitle. - Added debug messages to new Command objects. - Implemented CmdLogo, which implements the _logo command, for fun. - Removed unnecessary base class overrides from Cmd* objects.
This commit is contained in:
parent
02c2023dc4
commit
557440db0c
13 changed files with 215 additions and 141 deletions
103
src/Context.cpp
103
src/Context.cpp
|
@ -53,6 +53,7 @@ Context::Context ()
|
|||
, tdb ()
|
||||
, tdb2 ()
|
||||
, program ("")
|
||||
, commandLine ("")
|
||||
, file_override ("")
|
||||
, var_overrides ("")
|
||||
, cmd ()
|
||||
|
@ -73,27 +74,8 @@ Context::~Context ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Context::initialize2 (int argc, char** argv)
|
||||
{
|
||||
// TODO Capture the args.
|
||||
// TODO Capture any stdin args.
|
||||
// TODO Scan for rc:<file> overrides --> apply.
|
||||
// TODO Combine command line into one string.
|
||||
// TODO Load relevant rc file.
|
||||
Timer t ("Context::initialize2");
|
||||
|
||||
// TODO Instantiate built-in command objects.
|
||||
commands.push_back (Command::factory ("install"));
|
||||
|
||||
// TODO Instantiate extension command objects.
|
||||
// TODO Instantiate default command object.
|
||||
// TODO Instantiate column objects.
|
||||
// TODO Instantiate UDA objects.
|
||||
// TODO Instantiate format objects.
|
||||
// TODO Instantiate extension format objects.
|
||||
// TODO Hook: on-launch
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Context::initialize (int argc, char** argv)
|
||||
{
|
||||
// Capture the args.
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
|
@ -129,6 +111,34 @@ void Context::initialize (int argc, char** argv)
|
|||
}
|
||||
}
|
||||
|
||||
// TODO Scan for rc:<file> overrides --> apply.
|
||||
|
||||
// Combine command line into one string.
|
||||
join (commandLine, " ", args);
|
||||
|
||||
// TODO Load relevant rc file.
|
||||
|
||||
// Instantiate built-in command objects.
|
||||
commands.push_back (Command::factory ("exec"));
|
||||
commands.push_back (Command::factory ("install"));
|
||||
commands.push_back (Command::factory ("_logo"));
|
||||
|
||||
// TODO Instantiate extension command objects.
|
||||
// TODO Instantiate default command object.
|
||||
// TODO Instantiate extension UDA objects.
|
||||
// TODO Instantiate extension format objects.
|
||||
// TODO Hook: on-launch
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Context::initialize (int argc, char** argv)
|
||||
{
|
||||
// Capture the args.
|
||||
// ...
|
||||
|
||||
// Capture any stdin args.
|
||||
// ...
|
||||
|
||||
initialize ();
|
||||
|
||||
// Hook system init, plus post-start event occurring at the first possible
|
||||
|
@ -182,8 +192,10 @@ int Context::run ()
|
|||
std::string output;
|
||||
try
|
||||
{
|
||||
parse (); // Parse command line.
|
||||
rc = dispatch (output); // Dispatch to command handlers.
|
||||
parse (); // Parse command line.
|
||||
rc = dispatch2 (output); // Dispatch to new command handlers.
|
||||
if (rc)
|
||||
rc = dispatch (output); // Dispatch to old command handlers.
|
||||
}
|
||||
|
||||
catch (const std::string& error)
|
||||
|
@ -229,6 +241,28 @@ int Context::run ()
|
|||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Context::dispatch2 (std::string &out)
|
||||
{
|
||||
Timer t ("Context::dispatch2");
|
||||
|
||||
updateXtermTitle ();
|
||||
|
||||
std::vector <Command*>::iterator c;
|
||||
for (c = commands.begin (); c != commands.end (); ++c)
|
||||
{
|
||||
if ((*c)->implements (commandLine))
|
||||
{
|
||||
if (! (*c)->read_only ())
|
||||
tdb.gc ();
|
||||
|
||||
return (*c)->execute (commandLine, out);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Context::dispatch (std::string &out)
|
||||
{
|
||||
|
@ -236,16 +270,7 @@ int Context::dispatch (std::string &out)
|
|||
|
||||
Timer t ("Context::dispatch");
|
||||
|
||||
// For read-only commands, optionally update the xterm window title.
|
||||
// Why just the read-only commands? Because this capability is to answer the
|
||||
// question of 'what did I just do to generate this outout?'.
|
||||
if (config.getBoolean ("xterm.title") &&
|
||||
cmd.isReadOnlyCommand ())
|
||||
{
|
||||
std::string title;
|
||||
join (title, " ", args);
|
||||
std::cout << "]0;task " << title << "" << std::endl;
|
||||
}
|
||||
updateXtermTitle ();
|
||||
|
||||
// TODO Chain-of-command pattern dispatch.
|
||||
|
||||
|
@ -881,6 +906,7 @@ void Context::clear ()
|
|||
tdb.clear (); // TODO Obsolete
|
||||
// tdb2.clear ();
|
||||
program = "";
|
||||
commandLine = "";
|
||||
args.clear ();
|
||||
file_override = "";
|
||||
var_overrides = "";
|
||||
|
@ -998,6 +1024,19 @@ void Context::autoFilter (Filter& f)
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// This capability is to answer the question of 'what did I just do to generate
|
||||
// this output?'.
|
||||
void Context::updateXtermTitle ()
|
||||
{
|
||||
if (config.getBoolean ("xterm.title"))
|
||||
{
|
||||
std::string title;
|
||||
join (title, " ", args);
|
||||
std::cout << "]0;task " << title << "" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Context::header (const std::string& input)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue