Argument Parsing

- Obsoleted Command::exectute  'commandLine' argument.  It is worse
  than unnecessary, it is an uncategorized raw argument string, which
  is only really useful for the 'execute' command, which itself now
  calls Arguments::combine to reconstruct the command line string.
This commit is contained in:
Paul Beckingham 2011-06-04 12:28:50 -04:00
parent c2e1757fb6
commit 644d027a87
99 changed files with 397 additions and 289 deletions

View file

@ -26,10 +26,13 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream>
#include <sstream>
#include <algorithm>
#include <stdlib.h> #include <stdlib.h>
#include <sys/select.h> #include <sys/select.h>
#include <Context.h> #include <Context.h>
#include <Nibbler.h> #include <Nibbler.h>
#include <ViewText.h>
#include <text.h> #include <text.h>
#include <util.h> #include <util.h>
#include <Arguments.h> #include <Arguments.h>
@ -47,17 +50,29 @@ Arguments::~Arguments ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Add a pair for every argument, with a category of "".
void Arguments::capture (int argc, const char** argv) void Arguments::capture (int argc, const char** argv)
{ {
for (int i = 0; i < argc; ++i) for (int i = 0; i < argc; ++i)
if (i > 0) this->push_back (std::make_pair (argv[i], (i == 0 ? "program" : "")));
this->push_back (argv[i]);
categorize ();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Add a pair with a category of "".
void Arguments::capture (const std::string& arg)
{
this->push_back (std::make_pair (arg, ""));
categorize ();
}
////////////////////////////////////////////////////////////////////////////////
// Add a pair for every word from std::cin, with a category of "".
void Arguments::append_stdin () void Arguments::append_stdin ()
{ {
// Capture any stdin args. // Use 'select' to determine whether there is any std::cin content buffered
// before trying to read it, to prevent blocking.
struct timeval tv; struct timeval tv;
fd_set fds; fd_set fds;
tv.tv_sec = 0; tv.tv_sec = 0;
@ -70,12 +85,94 @@ void Arguments::append_stdin ()
std::string arg; std::string arg;
while (std::cin >> arg) while (std::cin >> arg)
{ {
// It the terminator token is found, stop reading.
if (arg == "--") if (arg == "--")
break; break;
this->push_back (arg); this->push_back (std::make_pair (arg, ""));
} }
} }
categorize ();
}
////////////////////////////////////////////////////////////////////////////////
// Scan all the arguments, and assign a category.
void Arguments::categorize ()
{
bool terminated = false;
// Generate a vector of command keywords against which autoComplete can run.
std::vector <std::string> keywords;
std::map <std::string, Command*>::iterator k;
for (k = context.commands.begin (); k != context.commands.end (); ++k)
keywords.push_back (k->first);
// First scan for a command.
std::vector <std::pair <std::string, std::string> >::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg)
{
if (arg->first == "--")
break;
std::vector <std::string> matches;
if (autoComplete (arg->first, keywords, matches) == 1)
{
if (arg->first != matches[0])
context.debug ("Arguments::categorize keyword '" + arg->first + "' --> '" + matches[0] + "'");
else
context.debug ("Arguments::categorize keyword '" + arg->first + "'");
// Not only categorize the command, but overwrite the original command
// the fule name.
arg->first = matches[0];
arg->second = "command";
// Only the first match is a command.
break;
}
}
// Now categorize every uncategorized argument.
for (arg = this->begin (); arg != this->end (); ++arg)
{
if (!terminated)
{
// Nothing after -- is to be interpreted in any way.
if (arg->first == "--")
{
terminated = true;
arg->second = "terminator";
}
// // Only categorize uncategorized args.
// else if (arg->second == "")
else
{
// rc:<file>
if (arg->first.substr (0, 3) == "rc:")
arg->second = "rc";
// rc.<name>[:=]<value>
else if (arg->first.substr (0, 3) == "rc.")
arg->second = "override";
// TODO Sequence
// TODO UUID
// TODO +tag
// TODO -tag
// TODO subst
// TODO attr
else if (arg->second == "")
arg->second = "word";
}
}
// All post-termination arguments are simply words.
else
arg->second = "word";
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -85,17 +182,13 @@ void Arguments::rc_override (
std::string& override) std::string& override)
{ {
// Is there an override for rc:<file>? // Is there an override for rc:<file>?
std::vector <std::string>::iterator arg; std::vector <std::pair <std::string, std::string> >::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
// Nothing after -- is to be interpreted in any way. if (arg->second == "rc")
if (*arg == "--")
break;
else if (arg->substr (0, 3) == "rc:")
{ {
override = *arg; override = arg->first;
rc = File (arg->substr (3)); rc = File (arg->first.substr (3));
home = rc; home = rc;
std::string::size_type last_slash = rc.data.rfind ("/"); std::string::size_type last_slash = rc.data.rfind ("/");
@ -104,9 +197,10 @@ void Arguments::rc_override (
else else
home = "."; home = ".";
this->erase (arg);
context.header ("Using alternate .taskrc file " + rc.data); // TODO i18n context.header ("Using alternate .taskrc file " + rc.data); // TODO i18n
break; // Must break - iterator is dead.
// Keep scanning, because if there are multiple rc:file arguments, we
// want the last one to dominate.
} }
} }
} }
@ -119,18 +213,22 @@ void Arguments::get_data_location (std::string& data)
data = location; data = location;
// Are there any overrides for data.location? // Are there any overrides for data.location?
std::vector <std::string>::iterator arg; std::vector <std::pair <std::string, std::string> >::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
if (*arg == "--") if (arg->second == "override")
break;
else if (arg->substr (0, 16) == "rc.data.location" &&
((*arg)[16] == ':' || (*arg)[16] == '='))
{ {
data = arg->substr (17); if (arg->first.substr (0, 16) == "rc.data.location" &&
(arg->first[16] == ':' || arg->first[16] == '='))
{
data = arg->first.substr (17);
context.header ("Using alternate data.location " + data); // TODO i18n context.header ("Using alternate data.location " + data); // TODO i18n
} }
} }
// Keep scanning, because if there are multiple rc:file arguments, we
// want the last one to dominate.
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -138,22 +236,14 @@ void Arguments::get_data_location (std::string& data)
// leaving only the plain args. // leaving only the plain args.
void Arguments::apply_overrides (std::string& var_overrides) void Arguments::apply_overrides (std::string& var_overrides)
{ {
std::vector <std::string> filtered; std::vector <std::pair <std::string, std::string> >::iterator arg;
bool foundTerminator = false;
std::vector <std::string>::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
if (*arg == "--") if (arg->second == "override")
{
foundTerminator = true;
filtered.push_back (*arg);
}
else if (!foundTerminator && arg->substr (0, 3) == "rc.")
{ {
std::string name; std::string name;
std::string value; std::string value;
Nibbler n (*arg); Nibbler n (arg->first);
if (n.getLiteral ("rc.") && // rc. if (n.getLiteral ("rc.") && // rc.
n.getUntilOneOf (":=", name) && // xxx n.getUntilOneOf (":=", name) && // xxx
n.skipN (1)) // : n.skipN (1)) // :
@ -161,22 +251,15 @@ void Arguments::apply_overrides (std::string& var_overrides)
n.getUntilEOS (value); // Don't care if it's blank. n.getUntilEOS (value); // Don't care if it's blank.
context.config.set (name, value); context.config.set (name, value);
context.footnote ("Configuration override " + arg->substr (3)); context.footnote ("Configuration override rc." + name + "=" + value);
// Overrides are retained for potential use by the default command. // Overrides are retained for potential use by the default command.
var_overrides += " " + *arg; var_overrides += " " + arg->first;
} }
else else
context.footnote ("Problem with override: " + *arg); context.footnote ("Problem with override: " + arg->first);
} }
else
filtered.push_back (*arg);
} }
// Overwrite args with the filtered subset.
this->clear ();
for (arg = filtered.begin (); arg != filtered.end (); ++arg)
this->push_back (*arg);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -187,22 +270,22 @@ void Arguments::resolve_aliases ()
std::vector <std::string> expanded; std::vector <std::string> expanded;
bool something = false; bool something = false;
std::vector <std::string>::iterator arg; std::vector <std::pair <std::string, std::string> >::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
std::map <std::string, std::string>::iterator match = std::map <std::string, std::string>::iterator match =
context.aliases.find (*arg); context.aliases.find (arg->first);
if (match != context.aliases.end ()) if (match != context.aliases.end ())
{ {
context.debug (std::string ("Arguments::resolve_aliases '") context.debug (std::string ("Arguments::resolve_aliases '")
+ *arg + arg->first
+ "' --> '" + "' --> '"
+ context.aliases[*arg] + context.aliases[arg->first]
+ "'"); + "'");
std::vector <std::string> words; std::vector <std::string> words;
splitq (words, context.aliases[*arg], ' '); splitq (words, context.aliases[arg->first], ' ');
std::vector <std::string>::iterator word; std::vector <std::string>::iterator word;
for (word = words.begin (); word != words.end (); ++word) for (word = words.begin (); word != words.end (); ++word)
@ -211,45 +294,59 @@ void Arguments::resolve_aliases ()
something = true; something = true;
} }
else else
expanded.push_back (*arg); expanded.push_back (arg->first);
} }
// Only overwrite if something happened. // Only overwrite if something happened.
if (something) if (something)
{ {
this->clear (); this->clear ();
for (arg = expanded.begin (); arg != expanded.end (); ++arg) std::vector <std::string>::iterator e;
this->push_back (*arg); for (e = expanded.begin (); e != expanded.end (); ++e)
this->push_back (std::make_pair (*e, ""));
// Must now re-categorize everything.
categorize ();
} }
} }
////////////////////////////////////////////////////////////////////////////////
std::vector <std::string> Arguments::list ()
{
std::vector <std::string> all;
std::vector <std::pair <std::string, std::string> >::iterator i;
for (i = this->begin (); i != this->end (); ++i)
all.push_back (i->first);
return all;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string Arguments::combine () std::string Arguments::combine ()
{ {
std::string combined; std::string combined;
join (combined, " ", *(std::vector <std::string>*)this);
std::vector <std::pair <std::string, std::string> >::iterator i;
for (i = this->begin (); i != this->end (); ++i)
{
if (i != this->begin ())
combined += " ";
combined += i->first;
}
return combined; return combined;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Given a vector of command keywords, scan all arguments and locate the first bool Arguments::find_command (std::string& command)
// argument that matches a keyword.
bool Arguments::extract_command (
const std::vector <std::string>& keywords,
std::string& command)
{ {
std::vector <std::string>::iterator arg; std::vector <std::pair <std::string, std::string> >::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
std::vector <std::string> matches; if (arg->second == "command")
if (autoComplete (*arg, keywords, matches) == 1)
{ {
if (*arg != matches[0]) command = arg->first;
context.debug ("Arguments::extract_command keyword '" + *arg + "' --> '" + matches[0] + "'");
else
context.debug ("Arguments::extract_command keyword '" + *arg + "'");
command = matches[0];
return true; return true;
} }
} }
@ -257,24 +354,6 @@ bool Arguments::extract_command (
return false; return false;
} }
////////////////////////////////////////////////////////////////////////////////
// TODO
void Arguments::remove_command (const std::string& command)
{
}
////////////////////////////////////////////////////////////////////////////////
// TODO
void Arguments::extract_filter ()
{
}
////////////////////////////////////////////////////////////////////////////////
// TODO
void Arguments::extract_modifications ()
{
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// A sequence can be: // A sequence can be:
// //
@ -300,6 +379,7 @@ void Arguments::extract_modifications ()
// //
void Arguments::extract_sequence (std::vector <int>& sequence) void Arguments::extract_sequence (std::vector <int>& sequence)
{ {
/*
sequence.clear (); sequence.clear ();
std::vector <int> kill; std::vector <int> kill;
@ -378,44 +458,52 @@ void Arguments::extract_sequence (std::vector <int>& sequence)
// Now remove args in the kill list. // Now remove args in the kill list.
for (unsigned int k = 0; k < kill.size (); ++k) for (unsigned int k = 0; k < kill.size (); ++k)
this->erase (this->begin () + kill[k]); this->erase (this->begin () + kill[k]);
*/
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TODO void Arguments::dump (const std::string& label)
void Arguments::extract_uuids (std::vector <std::string>& uuids)
{ {
uuids.clear (); // Set up a map of categories to colors.
std::map <std::string, Color> color_map;
color_map["program"] = Color ("white on blue");
color_map["command"] = Color ("black on cyan");
color_map["rc"] = Color ("bold white on red");
color_map["override"] = Color ("white on red");
color_map["none"] = Color ("white on gray3");
} Color color_debug (context.config.get ("color.debug"));
std::stringstream out;
//////////////////////////////////////////////////////////////////////////////// out << color_debug.colorize (label)
// TODO << "\n";
void Arguments::extract_attrs ()
{ ViewText view;
} view.width (context.getWidth ());
view.leftMargin (4);
//////////////////////////////////////////////////////////////////////////////// for (unsigned int i = 0; i < this->size (); ++i)
// TODO view.add (Column::factory ("string", ""));
void Arguments::extract_words ()
{ view.addRow ();
} view.addRow ();
//////////////////////////////////////////////////////////////////////////////// for (unsigned int i = 0; i < this->size (); ++i)
// TODO {
void Arguments::extract_tags () std::string arg = (*this)[i].first;
{ std::string category = (*this)[i].second;
}
Color c;
//////////////////////////////////////////////////////////////////////////////// if (color_map[category].nontrivial ())
// TODO c = color_map[category];
void Arguments::extract_pattern () else
{ c = color_map["none"];
}
view.set (0, i, arg, c);
//////////////////////////////////////////////////////////////////////////////// view.set (1, i, category, c);
// TODO }
void Arguments::extract_subst ()
{ out << view.render ();
context.debug (out.str ());
std::cout << out.str (); // TODO Remove
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -34,38 +34,40 @@
#define ARGUMENTS_SEQUENCE_MAX_RANGE 1000 #define ARGUMENTS_SEQUENCE_MAX_RANGE 1000
class Arguments : public std::vector <std::string> class Arguments : public std::vector <std::pair <std::string, std::string> >
{ {
public: public:
Arguments (); Arguments ();
~Arguments (); ~Arguments ();
void capture (int, const char**); void capture (int, const char**);
void capture (const std::string&);
void categorize ();
void append_stdin (); void append_stdin ();
void rc_override (std::string&, File&, std::string&); void rc_override (std::string&, File&, std::string&);
void get_data_location (std::string&); void get_data_location (std::string&);
void apply_overrides (std::string&); void apply_overrides (std::string&);
void resolve_aliases (); void resolve_aliases ();
std::vector <std::string> list ();
std::string combine (); std::string combine ();
bool extract_command (const std::vector <std::string>&, std::string&); bool find_command (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_filter ();
void extract_modifications (); void extract_modifications ();
*/
void extract_sequence (std::vector <int>&); void extract_sequence (std::vector <int>&);
/*
void extract_uuids (std::vector <std::string>&); void extract_uuids (std::vector <std::string>&);
void extract_attrs (); void extract_attrs ();
void extract_words (); void extract_words ();
void extract_tags (); void extract_tags ();
void extract_pattern (); void extract_pattern ();
void extract_subst (); void extract_subst ();
*/
void dump (const std::string&);
}; };
#endif #endif

View file

@ -36,10 +36,12 @@
#include <Directory.h> #include <Directory.h>
#include <Date.h> #include <Date.h>
#include <File.h> #include <File.h>
#include <Timer.h>
#include <Config.h> #include <Config.h>
#include <text.h> #include <text.h>
#include <util.h> #include <util.h>
#include <cmake.h> #include <cmake.h>
#include <i18n.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// This string is used in two ways: // This string is used in two ways:
@ -473,9 +475,10 @@ Config::Config (const std::string& file)
// //
void Config::load (const std::string& file, int nest /* = 1 */) void Config::load (const std::string& file, int nest /* = 1 */)
{ {
Timer timer ("Config::load (" + file + ")");
if (nest > 10) if (nest > 10)
throw std::string ("Configuration file nested to more than 10 levels deep" throw std::string (STRING_CONFIG_OVERNEST);
" - this has to be a mistake.");
// First time in, load the default values. // First time in, load the default values.
if (nest == 1) if (nest == 1)

View file

@ -44,8 +44,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Context::Context () Context::Context ()
: program ("") : rc_file ()
, rc_file ()
, data_dir () , data_dir ()
, extension_dir () , extension_dir ()
, config () , config ()
@ -55,7 +54,6 @@ Context::Context ()
, task () , task ()
, tdb () , tdb ()
, tdb2 () , tdb2 ()
, commandLine ("")
, file_override ("") , file_override ("")
, var_overrides ("") , var_overrides ("")
, dom () , dom ()
@ -63,7 +61,6 @@ Context::Context ()
, use_color (true) , use_color (true)
, verbosity_legacy (false) , verbosity_legacy (false)
, inShadow (false) , inShadow (false)
, command ("")
, terminal_width (0) , terminal_width (0)
, terminal_height (0) , terminal_height (0)
{ {
@ -81,7 +78,6 @@ void Context::initialize (int argc, const char** argv)
// char** argv --> std::vector <std::string> Context::args. // char** argv --> std::vector <std::string> Context::args.
// TODO Handle "cal" case here. // TODO Handle "cal" case here.
program = argv[0];
args.capture (argc, argv); args.capture (argc, argv);
// echo one two -- three | task zero --> task zero one two // echo one two -- three | task zero --> task zero one two
@ -117,9 +113,6 @@ void Context::initialize (int argc, const char** argv)
// Apply rc overrides to Context::config, capturing raw args for later use. // Apply rc overrides to Context::config, capturing raw args for later use.
args.apply_overrides (var_overrides); args.apply_overrides (var_overrides);
// Combine command line into one string.
commandLine = args.combine ();
// Initialize the color rules, if necessary. // Initialize the color rules, if necessary.
if (color ()) if (color ())
initializeColorRules (); initializeColorRules ();
@ -130,14 +123,6 @@ void Context::initialize (int argc, const char** argv)
// TODO Instantiate extension command objects. // TODO Instantiate extension command objects.
// TODO Instantiate default command object. // 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 UDA objects.
// TODO Instantiate extension format objects. // TODO Instantiate extension format objects.
@ -160,6 +145,8 @@ void Context::initialize (int argc, const char** argv)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int Context::run () int Context::run ()
{ {
Timer timer ("Context::run");
int rc; int rc;
std::string output; std::string output;
try try
@ -181,12 +168,16 @@ int Context::run ()
// Dump all debug messages, controlled by rc.debug. // Dump all debug messages, controlled by rc.debug.
if (config.getBoolean ("debug")) if (config.getBoolean ("debug"))
{
foreach (d, debugMessages) foreach (d, debugMessages)
if (color ()) if (color ())
std::cout << colorizeDebug (*d) << "\n"; std::cout << colorizeDebug (*d) << "\n";
else else
std::cout << *d << "\n"; std::cout << *d << "\n";
args.dump ("Argument categorization");
}
// Dump all headers, controlled by 'header' verbosity token. // Dump all headers, controlled by 'header' verbosity token.
if (verbose ("header")) if (verbose ("header"))
foreach (h, headers) foreach (h, headers)
@ -218,7 +209,8 @@ int Context::dispatch (std::string &out)
Timer t ("Context::dispatch"); Timer t ("Context::dispatch");
// Autocomplete args against keywords. // Autocomplete args against keywords.
if (command != "") std::string command;
if (args.find_command (command))
{ {
updateXtermTitle (); updateXtermTitle ();
@ -228,13 +220,13 @@ int Context::dispatch (std::string &out)
if (c->displays_id ()) if (c->displays_id ())
tdb.gc (); tdb.gc ();
return c->execute (commandLine, out); return c->execute (out);
} }
// TODO Need to invoke 'information' when a sequence/filter is present, but // TODO Need to invoke 'information' when a sequence/filter is present, but
// no command is specified. // no command is specified.
return commands["help"]->execute (commandLine, out); return commands["help"]->execute (out);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -265,6 +257,8 @@ bool Context::color ()
// No need to go through this again. // No need to go through this again.
determine_color_use = false; determine_color_use = false;
debug ("Context::color --> " + std::string (use_color ? "on" : "off"));
} }
// Cached result. // Cached result.
@ -294,6 +288,7 @@ bool Context::verbose (const std::string& token)
// TODO OBSOLETE // TODO OBSOLETE
void Context::shadow () void Context::shadow ()
{ {
/*
// Determine if shadow file is enabled. // Determine if shadow file is enabled.
File shadowFile (config.get ("shadow.file")); File shadowFile (config.get ("shadow.file"));
if (shadowFile.data != "") if (shadowFile.data != "")
@ -352,6 +347,7 @@ void Context::shadow ()
inShadow = false; inShadow = false;
} }
*/
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -708,8 +704,6 @@ void Context::clear ()
task = Task (); task = Task ();
tdb.clear (); // TODO Obsolete tdb.clear (); // TODO Obsolete
// tdb2.clear (); // tdb2.clear ();
program = "";
commandLine = "";
args.clear (); args.clear ();
file_override = ""; file_override = "";
var_overrides = ""; var_overrides = "";
@ -834,8 +828,11 @@ void Context::updateXtermTitle ()
{ {
if (config.getBoolean ("xterm.title")) if (config.getBoolean ("xterm.title"))
{ {
std::string command;
args.find_command (command);
std::string title; std::string title;
join (title, " ", args); join (title, " ", args.list ());
std::cout << "]0;task " << command << " " << title << "" << std::endl; std::cout << "]0;task " << command << " " << title << "" << std::endl;
} }
} }

View file

@ -102,7 +102,6 @@ public:
Task task; // TODO Obsolete Task task; // TODO Obsolete
TDB tdb; // TODO Obsolete TDB tdb; // TODO Obsolete
TDB2 tdb2; TDB2 tdb2;
std::string commandLine; // TODO Obsolete
std::string file_override; std::string file_override;
std::string var_overrides; std::string var_overrides;
std::map <std::string, std::string> aliases; std::map <std::string, std::string> aliases;
@ -123,7 +122,6 @@ public:
bool inShadow; bool inShadow;
std::map <std::string, Command*> commands; std::map <std::string, Command*> commands;
std::string command;
int terminal_width; int terminal_width;
int terminal_height; int terminal_height;

View file

@ -78,12 +78,12 @@ const std::string DOM::get (const std::string& name)
name.substr (0, 8) == "context.") name.substr (0, 8) == "context.")
{ {
if (name == "context.program") if (name == "context.program")
return context.program; return context.args[0].first;
else if (name == "context.args") else if (name == "context.args")
{ {
std::string combined; std::string combined;
join (combined, " ", context.args); join (combined, " ", context.args.list ());
return combined; return combined;
} }
else if (name == "context.width") else if (name == "context.width")

View file

@ -46,7 +46,7 @@ CmdAdd::CmdAdd ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdAdd::execute (const std::string&, std::string& output) int CmdAdd::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;

View file

@ -35,7 +35,7 @@ class CmdAdd : public Command
{ {
public: public:
CmdAdd (); CmdAdd ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -44,7 +44,7 @@ CmdAnnotate::CmdAnnotate ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdAnnotate::execute (const std::string&, std::string& output) int CmdAnnotate::execute (std::string& output)
{ {
int rc = 0; int rc = 0;

View file

@ -35,7 +35,7 @@ class CmdAnnotate : public Command
{ {
public: public:
CmdAnnotate (); CmdAnnotate ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -44,7 +44,7 @@ CmdAppend::CmdAppend ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdAppend::execute (const std::string&, std::string& output) int CmdAppend::execute (std::string& output)
{ {
if (!context.task.has ("description")) if (!context.task.has ("description"))
throw std::string ("Additional text must be provided."); throw std::string ("Additional text must be provided.");

View file

@ -35,7 +35,7 @@ class CmdAppend : public Command
{ {
public: public:
CmdAppend (); CmdAppend ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -978,7 +978,7 @@ CmdBurndownMonthly::CmdBurndownMonthly ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdBurndownMonthly::execute (const std::string&, std::string& output) int CmdBurndownMonthly::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
@ -1031,7 +1031,7 @@ CmdBurndownWeekly::CmdBurndownWeekly ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdBurndownWeekly::execute (const std::string&, std::string& output) int CmdBurndownWeekly::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
@ -1084,7 +1084,7 @@ CmdBurndownDaily::CmdBurndownDaily ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdBurndownDaily::execute (const std::string&, std::string& output) int CmdBurndownDaily::execute (std::string& output)
{ {
int rc = 0; int rc = 0;

View file

@ -35,21 +35,21 @@ class CmdBurndownMonthly : public Command
{ {
public: public:
CmdBurndownMonthly (); CmdBurndownMonthly ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdBurndownWeekly : public Command class CmdBurndownWeekly : public Command
{ {
public: public:
CmdBurndownWeekly (); CmdBurndownWeekly ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdBurndownDaily : public Command class CmdBurndownDaily : public Command
{ {
public: public:
CmdBurndownDaily (); CmdBurndownDaily ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -48,7 +48,7 @@ CmdCalendar::CmdCalendar ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCalendar::execute (const std::string&, std::string& output) int CmdCalendar::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
@ -114,8 +114,9 @@ int CmdCalendar::execute (const std::string&, std::string& output)
int argMonth = 0; int argMonth = 0;
int argYear = 0; int argYear = 0;
bool argWholeYear = false; bool argWholeYear = false;
std::vector <std::string> args = context.args.list ();
std::vector <std::string>::iterator arg; std::vector <std::string>::iterator arg;
for (arg = context.args.begin (); arg != context.args.end (); ++arg) for (arg = args.begin (); arg != args.end (); ++arg)
{ {
// Some version of "calendar". // Some version of "calendar".
if (autoComplete (lowerCase (*arg), commandNames, matches) == 1) if (autoComplete (lowerCase (*arg), commandNames, matches) == 1)
@ -353,7 +354,7 @@ int CmdCalendar::execute (const std::string&, std::string& output)
context.sequence.clear (); context.sequence.clear ();
std::string output; std::string output;
context.commands[report]->execute (context.commandLine, output); context.commands[report]->execute (output);
out << output; out << output;
} }

View file

@ -38,7 +38,7 @@ class CmdCalendar : public Command
{ {
public: public:
CmdCalendar (); CmdCalendar ();
int execute (const std::string&, std::string&); int execute (std::string&);
private: private:
std::string renderMonths (int, int, const Date&, std::vector <Task>&, int); std::string renderMonths (int, int, const Date&, std::vector <Task>&, int);

View file

@ -44,7 +44,7 @@ CmdColor::CmdColor ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdColor::execute (const std::string&, std::string& output) int CmdColor::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;

View file

@ -35,7 +35,7 @@ class CmdColor : public Command
{ {
public: public:
CmdColor (); CmdColor ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -45,7 +45,7 @@ CmdCompletionCommands::CmdCompletionCommands ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCompletionCommands::execute (const std::string&, std::string& output) int CmdCompletionCommands::execute (std::string& output)
{ {
// Get a list of all commands. // Get a list of all commands.
std::vector <std::string> commands; std::vector <std::string> commands;
@ -81,7 +81,7 @@ CmdZshCommands::CmdZshCommands ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdZshCommands::execute (const std::string&, std::string& output) int CmdZshCommands::execute (std::string& output)
{ {
// Get a list of all commands. // Get a list of all commands.
std::vector <std::string> commands; std::vector <std::string> commands;

View file

@ -35,14 +35,14 @@ class CmdCompletionCommands : public Command
{ {
public: public:
CmdCompletionCommands (); CmdCompletionCommands ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdZshCommands : public Command class CmdZshCommands : public Command
{ {
public: public:
CmdZshCommands (); CmdZshCommands ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -45,9 +45,12 @@ CmdConfig::CmdConfig ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdConfig::execute (const std::string&, std::string& output) int CmdConfig::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
/*
TODO Revise argument handling
std::stringstream out; std::stringstream out;
// Obtain the arguments from the description. That way, things like '--' // Obtain the arguments from the description. That way, things like '--'
@ -160,6 +163,7 @@ int CmdConfig::execute (const std::string&, std::string& output)
} }
else else
throw std::string ("Specify the name of a config variable to modify."); throw std::string ("Specify the name of a config variable to modify.");
*/
return rc; return rc;
} }
@ -176,7 +180,7 @@ CmdCompletionConfig::CmdCompletionConfig ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCompletionConfig::execute (const std::string&, std::string& output) int CmdCompletionConfig::execute (std::string& output)
{ {
std::vector <std::string> configs; std::vector <std::string> configs;
context.config.all (configs); context.config.all (configs);

View file

@ -35,14 +35,14 @@ class CmdConfig : public Command
{ {
public: public:
CmdConfig (); CmdConfig ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdCompletionConfig : public Command class CmdCompletionConfig : public Command
{ {
public: public:
CmdCompletionConfig (); CmdCompletionConfig ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -43,7 +43,7 @@ CmdCount::CmdCount ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCount::execute (const std::string&, std::string& output) int CmdCount::execute (std::string& output)
{ {
// Scan the pending tasks, applying any filter. // Scan the pending tasks, applying any filter.
std::vector <Task> tasks; std::vector <Task> tasks;

View file

@ -35,7 +35,7 @@ class CmdCount : public Command
{ {
public: public:
CmdCount (); CmdCount ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -51,7 +51,7 @@ CmdCustom::CmdCustom (
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCustom::execute (const std::string&, std::string& output) int CmdCustom::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
@ -128,7 +128,6 @@ int CmdCustom::execute (const std::string&, std::string& output)
//////////////////////////////////// ////////////////////////////////////
// TODO Create the filter // TODO Create the filter
context.args.remove_command (_keyword);
//std::vector <std::string> filter_args; //std::vector <std::string> filter_args;
//context.args.extract_filter (filter_args); //context.args.extract_filter (filter_args);

View file

@ -35,7 +35,7 @@ class CmdCustom : public Command
{ {
public: public:
CmdCustom (const std::string&, const std::string&, const std::string&); CmdCustom (const std::string&, const std::string&, const std::string&);
int execute (const std::string&, std::string&); int execute (std::string&);
private: private:
void validateReportColumns (std::vector <std::string>&); void validateReportColumns (std::vector <std::string>&);

View file

@ -45,7 +45,7 @@ CmdDelete::CmdDelete ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdDelete::execute (const std::string&, std::string& output) int CmdDelete::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;

View file

@ -35,7 +35,7 @@ class CmdDelete : public Command
{ {
public: public:
CmdDelete (); CmdDelete ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -45,7 +45,7 @@ CmdDenotate::CmdDenotate ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdDenotate::execute (const std::string&, std::string& output) int CmdDenotate::execute (std::string& output)
{ {
int rc = 0; int rc = 0;

View file

@ -35,7 +35,7 @@ class CmdDenotate : public Command
{ {
public: public:
CmdDenotate (); CmdDenotate ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -63,7 +63,7 @@ CmdDiagnostics::CmdDiagnostics ()
// //
// Although this will change over time, initially this command will answer the // Although this will change over time, initially this command will answer the
// kind of questions we always have to ask whenever something is wrong. // kind of questions we always have to ask whenever something is wrong.
int CmdDiagnostics::execute (const std::string&, std::string& output) int CmdDiagnostics::execute (std::string& output)
{ {
Color bold ("bold"); Color bold ("bold");

View file

@ -35,7 +35,7 @@ class CmdDiagnostics : public Command
{ {
public: public:
CmdDiagnostics (); CmdDiagnostics ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -44,7 +44,7 @@ CmdDone::CmdDone ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdDone::execute (const std::string&, std::string& output) int CmdDone::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
int count = 0; int count = 0;

View file

@ -35,7 +35,7 @@ class CmdDone : public Command
{ {
public: public:
CmdDone (); CmdDone ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -45,7 +45,7 @@ CmdDuplicate::CmdDuplicate ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdDuplicate::execute (const std::string&, std::string& output) int CmdDuplicate::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;

View file

@ -35,7 +35,7 @@ class CmdDuplicate : public Command
{ {
public: public:
CmdDuplicate (); CmdDuplicate ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -52,7 +52,7 @@ CmdEdit::CmdEdit ()
// Introducing the Silver Bullet. This feature is the catch-all fixative for // Introducing the Silver Bullet. This feature is the catch-all fixative for
// various other ills. This is like opening up the hood and going in with a // various other ills. This is like opening up the hood and going in with a
// wrench. To be used sparingly. // wrench. To be used sparingly.
int CmdEdit::execute (const std::string&, std::string& output) int CmdEdit::execute (std::string& output)
{ {
int rc = 0; int rc = 0;

View file

@ -36,7 +36,7 @@ class CmdEdit : public Command
{ {
public: public:
CmdEdit (); CmdEdit ();
int execute (const std::string&, std::string&); int execute (std::string&);
private: private:
std::string findValue (const std::string&, const std::string&); std::string findValue (const std::string&, const std::string&);

View file

@ -26,8 +26,11 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <stdlib.h> #include <stdlib.h>
#include <Context.h>
#include <CmdExec.h> #include <CmdExec.h>
extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdExec::CmdExec () CmdExec::CmdExec ()
{ {
@ -39,8 +42,17 @@ CmdExec::CmdExec ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdExec::execute (const std::string& command_line, std::string&) int CmdExec::execute (std::string& output)
{ {
std::string command_line;
std::vector <std::pair <std::string, std::string> >::iterator arg;
for (arg = context.args.begin (); arg != context.args.end (); ++arg)
{
if (arg != context.args.begin () &&
arg->first != "execute")
command_line += arg->first;
}
return system (command_line.c_str ()); return system (command_line.c_str ());
} }

View file

@ -35,7 +35,7 @@ class CmdExec : public Command
{ {
public: public:
CmdExec (); CmdExec ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -44,7 +44,7 @@ CmdHelp::CmdHelp ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdHelp::execute (const std::string&, std::string& output) int CmdHelp::execute (std::string& output)
{ {
ViewText view; ViewText view;
view.width (context.getWidth ()); view.width (context.getWidth ());

View file

@ -35,7 +35,7 @@ class CmdHelp : public Command
{ {
public: public:
CmdHelp (); CmdHelp ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -38,7 +38,6 @@ extern Context context;
CmdHistoryMonthly::CmdHistoryMonthly () CmdHistoryMonthly::CmdHistoryMonthly ()
{ {
_keyword = "history.monthly"; _keyword = "history.monthly";
_usage = "task execute <external command>";
_usage = "task history.monthly [<filter>]"; _usage = "task history.monthly [<filter>]";
_description = "Shows a report of task history, by month."; _description = "Shows a report of task history, by month.";
_read_only = true; _read_only = true;
@ -46,7 +45,7 @@ CmdHistoryMonthly::CmdHistoryMonthly ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdHistoryMonthly::execute (const std::string&, std::string& output) int CmdHistoryMonthly::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::map <time_t, int> groups; // Represents any month with data std::map <time_t, int> groups; // Represents any month with data
@ -202,7 +201,7 @@ CmdHistoryAnnual::CmdHistoryAnnual ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdHistoryAnnual::execute (const std::string&, std::string& output) int CmdHistoryAnnual::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::map <time_t, int> groups; // Represents any month with data std::map <time_t, int> groups; // Represents any month with data
@ -355,7 +354,7 @@ CmdGHistoryMonthly::CmdGHistoryMonthly ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdGHistoryMonthly::execute (const std::string&, std::string& output) int CmdGHistoryMonthly::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::map <time_t, int> groups; // Represents any month with data std::map <time_t, int> groups; // Represents any month with data
@ -551,7 +550,7 @@ CmdGHistoryAnnual::CmdGHistoryAnnual ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdGHistoryAnnual::execute (const std::string&, std::string& output) int CmdGHistoryAnnual::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::map <time_t, int> groups; // Represents any month with data std::map <time_t, int> groups; // Represents any month with data

View file

@ -35,28 +35,28 @@ class CmdHistoryMonthly : public Command
{ {
public: public:
CmdHistoryMonthly (); CmdHistoryMonthly ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdHistoryAnnual : public Command class CmdHistoryAnnual : public Command
{ {
public: public:
CmdHistoryAnnual (); CmdHistoryAnnual ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdGHistoryMonthly : public Command class CmdGHistoryMonthly : public Command
{ {
public: public:
CmdGHistoryMonthly (); CmdGHistoryMonthly ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdGHistoryAnnual : public Command class CmdGHistoryAnnual : public Command
{ {
public: public:
CmdGHistoryAnnual (); CmdGHistoryAnnual ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -45,7 +45,7 @@ CmdIDs::CmdIDs ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdIDs::execute (const std::string&, std::string& output) int CmdIDs::execute (std::string& output)
{ {
// Scan the pending tasks, applying any filter. // Scan the pending tasks, applying any filter.
std::vector <Task> tasks; std::vector <Task> tasks;
@ -78,7 +78,7 @@ CmdCompletionIds::CmdCompletionIds ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCompletionIds::execute (const std::string&, std::string& output) int CmdCompletionIds::execute (std::string& output)
{ {
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking")); context.tdb.lock (context.config.getBoolean ("locking"));
@ -116,7 +116,7 @@ CmdZshCompletionIds::CmdZshCompletionIds ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdZshCompletionIds::execute (const std::string&, std::string& output) int CmdZshCompletionIds::execute (std::string& output)
{ {
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking")); context.tdb.lock (context.config.getBoolean ("locking"));

View file

@ -35,21 +35,21 @@ class CmdIDs : public Command
{ {
public: public:
CmdIDs (); CmdIDs ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdCompletionIds : public Command class CmdCompletionIds : public Command
{ {
public: public:
CmdCompletionIds (); CmdCompletionIds ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdZshCompletionIds : public Command class CmdZshCompletionIds : public Command
{ {
public: public:
CmdZshCompletionIds (); CmdZshCompletionIds ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -739,6 +739,7 @@ std::string CmdImport::todoSh_2_0 (const std::vector <std::string>& lines)
std::vector <std::string>::const_iterator it; std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
{ {
/*
try try
{ {
context.args.clear (); context.args.clear ();
@ -802,12 +803,10 @@ std::string CmdImport::todoSh_2_0 (const std::vector <std::string>& lines)
} }
} }
/* // context.task.clear ();
context.task.clear (); // context.cmd.command = "";
context.cmd.command = ""; // context.parse ();
context.parse (); // decorateTask (context.task);
decorateTask (context.task);
*/
// Override the Task::pending that decorateTask applies. // Override the Task::pending that decorateTask applies.
if (!isPending) if (!isPending)
@ -837,6 +836,7 @@ std::string CmdImport::todoSh_2_0 (const std::vector <std::string>& lines)
context.clearMessages (); context.clearMessages ();
failed.push_back (*it); failed.push_back (*it);
} }
*/
} }
context.tdb.commit (); context.tdb.commit ();
@ -869,6 +869,7 @@ std::string CmdImport::text (const std::vector <std::string>& lines)
std::vector <std::string>::const_iterator it; std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it) for (it = lines.begin (); it != lines.end (); ++it)
{ {
/*
std::string line = *it; std::string line = *it;
// Strip comments // Strip comments
@ -885,12 +886,10 @@ std::string CmdImport::text (const std::vector <std::string>& lines)
context.args.clear (); context.args.clear ();
split (context.args, std::string ("add ") + line, ' '); split (context.args, std::string ("add ") + line, ' ');
/* // context.task.clear ();
context.task.clear (); // context.cmd.command = "";
context.cmd.command = ""; // context.parse ();
context.parse (); // decorateTask (context.task);
decorateTask (context.task);
*/
context.tdb.add (context.task); context.tdb.add (context.task);
context.clearMessages (); context.clearMessages ();
@ -902,6 +901,7 @@ std::string CmdImport::text (const std::vector <std::string>& lines)
failed.push_back (line); failed.push_back (line);
} }
} }
*/
} }
context.tdb.commit (); context.tdb.commit ();
@ -1284,7 +1284,7 @@ std::string CmdImport::YAML (const std::vector <std::string>& lines)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdImport::execute (const std::string&, std::string& output) int CmdImport::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;

View file

@ -35,7 +35,7 @@ class CmdImport : public Command
{ {
public: public:
CmdImport (); CmdImport ();
int execute (const std::string&, std::string&); int execute (std::string&);
private: private:
enum fileType enum fileType

View file

@ -47,7 +47,7 @@ CmdInfo::CmdInfo ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdInfo::execute (const std::string&, std::string& output) int CmdInfo::execute (std::string& output)
{ {
int rc = 0; int rc = 0;

View file

@ -35,7 +35,7 @@ class CmdInfo : public Command
{ {
public: public:
CmdInfo (); CmdInfo ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -47,7 +47,7 @@ CmdInstall::CmdInstall ()
// Generate UUID // Generate UUID
// Call the "install" function once, store results in rc: // Call the "install" function once, store results in rc:
// extension.<uuid>=<JSON> // extension.<uuid>=<JSON>
int CmdInstall::execute (const std::string&, std::string&) int CmdInstall::execute (std::string&)
{ {
return 1; return 1;
} }

View file

@ -35,7 +35,7 @@ class CmdInstall : public Command
{ {
public: public:
CmdInstall (); CmdInstall ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -45,7 +45,7 @@ CmdLog::CmdLog ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdLog::execute (const std::string&, std::string& output) int CmdLog::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;

View file

@ -35,7 +35,7 @@ class CmdLog : public Command
{ {
public: public:
CmdLog (); CmdLog ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -47,7 +47,7 @@ CmdLogo::CmdLogo ()
// Generate UUID // Generate UUID
// Call the "install" function once, store results in rc: // Call the "install" function once, store results in rc:
// extension.<uuid>=<JSON> // extension.<uuid>=<JSON>
int CmdLogo::execute (const std::string&, std::string& output) int CmdLogo::execute (std::string& output)
{ {
static const char* data[] = static const char* data[] =
{ {

View file

@ -35,7 +35,7 @@ class CmdLogo : public Command
{ {
public: public:
CmdLogo (); CmdLogo ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -47,7 +47,7 @@ CmdMerge::CmdMerge ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdMerge::execute (const std::string&, std::string& output) int CmdMerge::execute (std::string& output)
{ {
std::string file = trim (context.task.get ("description")); std::string file = trim (context.task.get ("description"));
std::string pushfile = ""; std::string pushfile = "";
@ -93,7 +93,7 @@ int CmdMerge::execute (const std::string&, std::string& output)
context.task.set ("description", uri.data); context.task.set ("description", uri.data);
std::string out; std::string out;
context.commands["push"]->execute ("", out); context.commands["push"]->execute (out);
} }
} }
else else

View file

@ -35,7 +35,7 @@ class CmdMerge : public Command
{ {
public: public:
CmdMerge (); CmdMerge ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -48,7 +48,7 @@ CmdModify::CmdModify ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdModify::execute (const std::string&, std::string& output) int CmdModify::execute (std::string& output)
{ {
int count = 0; int count = 0;
std::stringstream out; std::stringstream out;

View file

@ -35,7 +35,7 @@ class CmdModify : public Command
{ {
public: public:
CmdModify (); CmdModify ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -44,7 +44,7 @@ CmdPrepend::CmdPrepend ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdPrepend::execute (const std::string&, std::string& output) int CmdPrepend::execute (std::string& output)
{ {
if (!context.task.has ("description")) if (!context.task.has ("description"))
throw std::string ("Additional text must be provided."); throw std::string ("Additional text must be provided.");

View file

@ -35,7 +35,7 @@ class CmdPrepend : public Command
{ {
public: public:
CmdPrepend (); CmdPrepend ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -44,7 +44,7 @@ CmdProjects::CmdProjects ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdProjects::execute (const std::string&, std::string& output) int CmdProjects::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;
@ -142,7 +142,7 @@ CmdCompletionProjects::CmdCompletionProjects ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCompletionProjects::execute (const std::string&, std::string& output) int CmdCompletionProjects::execute (std::string& output)
{ {
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking")); context.tdb.lock (context.config.getBoolean ("locking"));

View file

@ -35,14 +35,14 @@ class CmdProjects : public Command
{ {
public: public:
CmdProjects (); CmdProjects ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdCompletionProjects : public Command class CmdCompletionProjects : public Command
{ {
public: public:
CmdCompletionProjects (); CmdCompletionProjects ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -46,7 +46,7 @@ CmdPull::CmdPull ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdPull::execute (const std::string&, std::string& output) int CmdPull::execute (std::string& output)
{ {
std::string file = trim (context.task.get ("description")); std::string file = trim (context.task.get ("description"));

View file

@ -35,7 +35,7 @@ class CmdPull : public Command
{ {
public: public:
CmdPull (); CmdPull ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -48,7 +48,7 @@ CmdPush::CmdPush ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Transfers the local data (from rc.location.data) to the remote path. Because // Transfers the local data (from rc.location.data) to the remote path. Because
// this is potentially on another machine, no checking can be performed. // this is potentially on another machine, no checking can be performed.
int CmdPush::execute (const std::string&, std::string& output) int CmdPush::execute (std::string& output)
{ {
std::string file = trim (context.task.get ("description")); std::string file = trim (context.task.get ("description"));

View file

@ -35,7 +35,7 @@ class CmdPush : public Command
{ {
public: public:
CmdPush (); CmdPush ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -42,7 +42,7 @@ CmdQuery::CmdQuery ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdQuery::execute (const std::string&, std::string& output) int CmdQuery::execute (std::string& output)
{ {
int rc = 0; int rc = 0;

View file

@ -35,7 +35,7 @@ class CmdQuery : public Command
{ {
public: public:
CmdQuery (); CmdQuery ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -45,7 +45,7 @@ CmdReports::CmdReports ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdReports::execute (const std::string&, std::string& output) int CmdReports::execute (std::string& output)
{ {
std::vector <std::string> reports; std::vector <std::string> reports;

View file

@ -35,7 +35,7 @@ class CmdReports : public Command
{ {
public: public:
CmdReports (); CmdReports ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -45,7 +45,7 @@ CmdShell::CmdShell ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdShell::execute (const std::string&, std::string&) int CmdShell::execute (std::string&)
{ {
// Display some kind of welcome message. // Display some kind of welcome message.
Color bold (Color::nocolor, Color::nocolor, false, true, false); Color bold (Color::nocolor, Color::nocolor, false, true, false);
@ -85,6 +85,7 @@ int CmdShell::execute (const std::string&, std::string&)
{ {
try try
{ {
/*
context.clear (); context.clear ();
std::vector <std::string> args; std::vector <std::string> args;
split (args, decoratedCommand, ' '); split (args, decoratedCommand, ' ');
@ -94,6 +95,7 @@ int CmdShell::execute (const std::string&, std::string&)
context.initialize (0, NULL); context.initialize (0, NULL);
context.run (); context.run ();
*/
} }
catch (std::string& error) catch (std::string& error)

View file

@ -35,7 +35,7 @@ class CmdShell : public Command
{ {
public: public:
CmdShell (); CmdShell ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -50,9 +50,10 @@ CmdShow::CmdShow ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdShow::execute (const std::string&, std::string& output) int CmdShow::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
/*
std::stringstream out; std::stringstream out;
// Obtain the arguments from the description. That way, things like '--' // Obtain the arguments from the description. That way, things like '--'
@ -308,6 +309,7 @@ int CmdShow::execute (const std::string&, std::string& output)
} }
output = out.str (); output = out.str ();
*/
return rc; return rc;
} }

View file

@ -35,7 +35,7 @@ class CmdShow : public Command
{ {
public: public:
CmdShow (); CmdShow ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -43,7 +43,7 @@ CmdStart::CmdStart ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdStart::execute (const std::string&, std::string& output) int CmdStart::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;

View file

@ -35,7 +35,7 @@ class CmdStart : public Command
{ {
public: public:
CmdStart (); CmdStart ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -49,7 +49,7 @@ CmdStatistics::CmdStatistics ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdStatistics::execute (const std::string&, std::string& output) int CmdStatistics::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;

View file

@ -35,7 +35,7 @@ class CmdStatistics : public Command
{ {
public: public:
CmdStatistics (); CmdStatistics ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -43,7 +43,7 @@ CmdStop::CmdStop ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdStop::execute (const std::string&, std::string& output) int CmdStop::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;

View file

@ -35,7 +35,7 @@ class CmdStop : public Command
{ {
public: public:
CmdStop (); CmdStop ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -50,7 +50,7 @@ CmdSummary::CmdSummary ()
// Project Remaining Avg Age Complete 0% 100% // Project Remaining Avg Age Complete 0% 100%
// A 12 13d 55% XXXXXXXXXXXXX----------- // A 12 13d 55% XXXXXXXXXXXXX-----------
// B 109 3d 12h 10% XXX--------------------- // B 109 3d 12h 10% XXX---------------------
int CmdSummary::execute (const std::string&, std::string& output) int CmdSummary::execute (std::string& output)
{ {
int rc = 0; int rc = 0;

View file

@ -35,7 +35,7 @@ class CmdSummary : public Command
{ {
public: public:
CmdSummary (); CmdSummary ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -46,7 +46,7 @@ CmdTags::CmdTags ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdTags::execute (const std::string&, std::string& output) int CmdTags::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
std::stringstream out; std::stringstream out;
@ -131,7 +131,7 @@ CmdCompletionTags::CmdCompletionTags ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCompletionTags::execute (const std::string&, std::string& output) int CmdCompletionTags::execute (std::string& output)
{ {
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking")); context.tdb.lock (context.config.getBoolean ("locking"));

View file

@ -35,14 +35,14 @@ class CmdTags : public Command
{ {
public: public:
CmdTags (); CmdTags ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdCompletionTags : public Command class CmdCompletionTags : public Command
{ {
public: public:
CmdCompletionTags (); CmdCompletionTags ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -46,7 +46,7 @@ CmdTimesheet::CmdTimesheet ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdTimesheet::execute (const std::string&, std::string& output) int CmdTimesheet::execute (std::string& output)
{ {
int rc = 0; int rc = 0;

View file

@ -35,7 +35,7 @@ class CmdTimesheet : public Command
{ {
public: public:
CmdTimesheet (); CmdTimesheet ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -42,7 +42,7 @@ CmdTip::CmdTip ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdTip::execute (const std::string&, std::string&) int CmdTip::execute (std::string&)
{ {
// TODO Read tips file, pick one, display it. // TODO Read tips file, pick one, display it.
return 0; return 0;

View file

@ -35,7 +35,7 @@ class CmdTip : public Command
{ {
public: public:
CmdTip (); CmdTip ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -41,7 +41,7 @@ CmdUndo::CmdUndo ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdUndo::execute (const std::string&, std::string& output) int CmdUndo::execute (std::string& output)
{ {
context.disallowModification (); context.disallowModification ();

View file

@ -35,7 +35,7 @@ class CmdUndo : public Command
{ {
public: public:
CmdUndo (); CmdUndo ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -44,7 +44,7 @@ CmdUrgency::CmdUrgency ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdUrgency::execute (const std::string&, std::string& output) int CmdUrgency::execute (std::string& output)
{ {
// Get all the tasks. // Get all the tasks.
std::vector <Task> tasks; std::vector <Task> tasks;

View file

@ -35,7 +35,7 @@ class CmdUrgency : public Command
{ {
public: public:
CmdUrgency (); CmdUrgency ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -46,7 +46,7 @@ CmdVersion::CmdVersion ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdVersion::execute (const std::string&, std::string& output) int CmdVersion::execute (std::string& output)
{ {
std::stringstream out; std::stringstream out;
@ -128,9 +128,7 @@ CmdCompletionVersion::CmdCompletionVersion ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdCompletionVersion::execute ( int CmdCompletionVersion::execute (std::string& output)
const std::string&,
std::string& output)
{ {
#ifdef HAVE_COMMIT #ifdef HAVE_COMMIT
output = COMMIT; output = COMMIT;

View file

@ -35,14 +35,14 @@ class CmdVersion : public Command
{ {
public: public:
CmdVersion (); CmdVersion ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
class CmdCompletionVersion : public Command class CmdCompletionVersion : public Command
{ {
public: public:
CmdCompletionVersion (); CmdCompletionVersion ();
int execute (const std::string&, std::string&); int execute (std::string&);
}; };
#endif #endif

View file

@ -47,7 +47,7 @@ public:
std::string description () const; std::string description () const;
bool read_only () const; bool read_only () const;
bool displays_id () const; bool displays_id () const;
virtual int execute (const std::string&, std::string&) = 0; virtual int execute (std::string&) = 0;
protected: protected:
std::string _keyword; std::string _keyword;

View file

@ -108,6 +108,9 @@
#define STRING_CMD_SHOW_CONF_VAR "Config Variable" #define STRING_CMD_SHOW_CONF_VAR "Config Variable"
#define STRING_CMD_SHOW_CONF_VALUE "Value" #define STRING_CMD_SHOW_CONF_VALUE "Value"
// Config
#define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake."
// Context // Context
#define STRING_CONTEXT_CREATE_RC "A configuration file could not be found in {1}\n\nWould you like a sample {2} created, so taskwarrior can proceed?" #define STRING_CONTEXT_CREATE_RC "A configuration file could not be found in {1}\n\nWould you like a sample {2} created, so taskwarrior can proceed?"
#define STRING_CONTEXT_NEED_RC "Cannot proceed without rc file." #define STRING_CONTEXT_NEED_RC "Cannot proceed without rc file."

View file

@ -40,7 +40,7 @@
Context context; Context context;
int main (int argc, char** argv) int main (int argc, const char** argv)
{ {
// Set up randomness. // Set up randomness.
#ifdef CYGWIN #ifdef CYGWIN
@ -63,7 +63,7 @@ int main (int argc, char** argv)
try try
{ {
context.initialize (argc, (const char**)argv); context.initialize (argc, argv);
status = context.run (); status = context.run ();
} }