- Prepared CmdCustom for new command line processing code.
This commit is contained in:
Paul Beckingham 2011-06-02 00:47:05 -04:00
parent a3912d9123
commit e19f087931
5 changed files with 60 additions and 20 deletions

View file

@ -257,6 +257,12 @@ bool Arguments::extract_command (
return false;
}
////////////////////////////////////////////////////////////////////////////////
// TODO
void Arguments::remove_command (const std::string& command)
{
}
////////////////////////////////////////////////////////////////////////////////
// TODO
void Arguments::extract_filter ()

View file

@ -49,6 +49,13 @@ public:
std::string combine ();
bool extract_command (const std::vector <std::string>&, std::string&);
void remove_command (const std::string&);
/*
void extract_read_only (command, filter);
void extract_write_commands (filter, command, mods);
*/
void extract_filter ();
void extract_modifications ();

View file

@ -63,6 +63,7 @@ Context::Context ()
, use_color (true)
, verbosity_legacy (false)
, inShadow (false)
, command ("")
, terminal_width (0)
, terminal_height (0)
{
@ -128,6 +129,15 @@ void Context::initialize (int argc, const char** argv)
// TODO Instantiate extension command objects.
// TODO Instantiate default command object.
// Create list of all command keywords.
std::vector <std::string> keywords;
std::map <std::string, Command*>::iterator i;
for (i = commands.begin (); i != commands.end (); ++i)
keywords.push_back (i->first);
args.extract_command (keywords, command);
// TODO Instantiate extension UDA objects.
// TODO Instantiate extension format objects.
@ -207,18 +217,11 @@ int Context::dispatch (std::string &out)
{
Timer t ("Context::dispatch");
updateXtermTitle ();
// Create list of all command keywords.
std::vector <std::string> keywords;
std::map <std::string, Command*>::iterator i;
for (i = commands.begin (); i != commands.end (); ++i)
keywords.push_back (i->first);
// Autocomplete args against keywords.
std::string command;
if (args.extract_command (keywords, command))
if (command != "")
{
updateXtermTitle ();
Command* c = commands[command];
// GC is invoked prior to running any command that displays task IDs.
@ -838,7 +841,7 @@ void Context::updateXtermTitle ()
{
std::string title;
join (title, " ", args);
std::cout << "]0;task " << title << "" << std::endl;
std::cout << "]0;task " << command << " " << title << "" << std::endl;
}
}

View file

@ -96,18 +96,18 @@ public:
Directory extension_dir;
Config config;
Filter filter;
Sequence sequence;
Subst subst;
Task task;
Filter filter; // TODO Obsolete
Sequence sequence; // TODO Obsolete
Subst subst; // TODO Obsolete
Task task; // TODO Obsolete
TDB tdb; // TODO Obsolete
TDB2 tdb2;
std::string commandLine;
std::string commandLine; // TODO Obsolete
std::string file_override;
std::string var_overrides;
std::map <std::string, std::string> aliases;
std::vector <std::string> tagAdditions;
std::vector <std::string> tagRemovals;
std::vector <std::string> tagAdditions; // TODO Obsolete
std::vector <std::string> tagRemovals; // TODO Obsolete
Hooks hooks;
DOM dom;
@ -123,6 +123,7 @@ public:
bool inShadow;
std::map <std::string, Command*> commands;
std::string command;
int terminal_width;
int terminal_height;

View file

@ -81,11 +81,13 @@ int CmdCustom::execute (const std::string&, std::string& output)
split (sortOrder, reportSort, ',');
validateSortColumns (sortOrder);
/*
// Apply rc overrides.
std::vector <std::string> filterArgs;
std::vector <std::string> filteredArgs;
split (filterArgs, reportFilter, ' ');
// context.applyOverrides (filterArgs, filteredArgs);
*/
/*
{
@ -108,17 +110,35 @@ int CmdCustom::execute (const std::string&, std::string& output)
}
*/
// Get all the tasks.
// Load the data.
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence ();
context.tdb.load (tasks, context.filter);
// context.tdb.load (tasks, context.filter);
Filter filter;
context.tdb.load (tasks, filter); // TODO No filter.
context.tdb.commit ();
context.tdb.unlock ();
/*
// Filter sequence.
if (context.sequence.size ())
context.filter.applySequence (tasks, context.sequence);
*/
////////////////////////////////////
// TODO Create the filter
context.args.remove_command (_keyword);
//std::vector <std::string> filter_args;
//context.args.extract_filter (filter_args);
// TODO Apply the filter
// Filter filter (context.args);
// std::vector <Task> filtered;
// thing.eval (filtered, context.args, tasks);
////////////////////////////////////
// Sort the tasks.
std::vector <int> sequence;
@ -150,6 +170,7 @@ int CmdCustom::execute (const std::string&, std::string& output)
}
// How many lines taken up by table header?
// TODO Consider rc.verbose
int table_header;
if (context.color () && context.config.getBoolean ("fontunderline"))
table_header = 1; // Underlining doesn't use extra line.
@ -162,6 +183,7 @@ int CmdCustom::execute (const std::string&, std::string& output)
getLimits (_keyword, maxrows, maxlines);
// Adjust for fluff in the output.
// TODO Consider rc.verbose
if (maxlines)
maxlines -= (context.verbose ("blank") ? 1 : 0)
+ table_header
@ -169,6 +191,7 @@ int CmdCustom::execute (const std::string&, std::string& output)
+ context.footnotes.size ();
// Render.
// TODO Consider rc.verbose
std::stringstream out;
if (tasks.size ())
{