- Added Lexer::Type arg to ::addArg, for future capture of type.
- Cleaned up code formatting from patch.
This commit is contained in:
Paul Beckingham 2015-03-07 17:29:08 -05:00
parent d202691638
commit 7826c7b988
3 changed files with 12 additions and 15 deletions

View file

@ -220,16 +220,14 @@ const std::string A::dump () const
// Static method. // Static method.
void CLI::getOverride (int argc, const char** argv, std::string& home, File& rc) void CLI::getOverride (int argc, const char** argv, std::string& home, File& rc)
{ {
bool terminated = false;
for (int i = 0; i < argc; ++i) for (int i = 0; i < argc; ++i)
{ {
std::string raw = argv[i]; std::string raw = argv[i];
if (raw == "--") if (raw == "--")
terminated = true; return;
if (! terminated && if (raw.length () > 3 &&
raw.length () > 3 &&
raw.substr (0, 3) == "rc:") raw.substr (0, 3) == "rc:")
{ {
rc = raw.substr (3); rc = raw.substr (3);
@ -379,10 +377,9 @@ void CLI::addContextFilter ()
{ {
// Detect if any context is set, and bail out if not // Detect if any context is set, and bail out if not
std::string contextName = context.config.get ("context"); std::string contextName = context.config.get ("context");
if (contextName == "") if (contextName == "")
{ {
context.debug("No context applied."); context.debug ("No context applied.");
return; return;
} }
@ -392,35 +389,35 @@ void CLI::addContextFilter ()
std::vector <A>::const_iterator a; std::vector <A>::const_iterator a;
for (a = _args.begin (); a != _args.end (); ++a) for (a = _args.begin (); a != _args.end (); ++a)
{ {
// TODO This looks wrong.
if (a->hasTag ("FILTER") && if (a->hasTag ("FILTER") &&
a->hasTag ("ATTRIBUTE") && a->hasTag ("ATTRIBUTE") &&
! a->hasTag ("TERMINATED") && ! a->hasTag ("TERMINATED") &&
! a->hasTag ("WORD") && ! a->hasTag ("WORD") &&
(a->attribute ("raw") == "id" || a->attribute ("raw") == "uuid")) (a->attribute ("raw") == "id" || a->attribute ("raw") == "uuid"))
{ {
context.debug(format("UUID/ID lexeme found '{1}', not applying context.", a->attribute ("raw"))); context.debug (format ("UUID/ID lexeme found '{1}', not applying context.", a->attribute ("raw")));
return; return;
} }
} }
} }
// Apply context // Apply context
context.debug("Applying context: " + contextName); context.debug ("Applying context: " + contextName);
std::string contextFilter = context.config.get ("context." + contextName); std::string contextFilter = context.config.get ("context." + contextName);
if (contextFilter == "") if (contextFilter == "")
context.debug("Context '" + contextName + "' not defined!"); context.debug ("Context '" + contextName + "' not defined.");
else else
{ {
addRawFilter("( " + contextFilter + " )"); addRawFilter ("( " + contextFilter + " )");
if (context.verbose ("context")) if (context.verbose ("context"))
context.footnote (format("Context '{1}' set. Use 'task context none' to remove.", contextName)); context.footnote (format ("Context '{1}' set. Use 'task context none' to remove.", contextName));
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Process raw string into parsed filter. // Process raw string into parsed filter.
//
void CLI::addRawFilter (const std::string& arg) void CLI::addRawFilter (const std::string& arg)
{ {
std::string lexeme; std::string lexeme;
@ -689,7 +686,7 @@ const std::string CLI::dump (const std::string& title /* = "CLI Parser" */) cons
// be lexed from those that need to be left alone. // be lexed from those that need to be left alone.
// //
// Either the arg is appended to _original_args intact, or the lexemes are. // Either the arg is appended to _original_args intact, or the lexemes are.
void CLI::addArg (const std::string& arg) void CLI::addArg (const std::string& arg, Lexer::Type type /* = Lexer::Type::word */)
{ {
std::string raw = trim (arg); std::string raw = trim (arg);

View file

@ -90,7 +90,7 @@ public:
const std::string dump (const std::string& title = "CLI Parser") const; const std::string dump (const std::string& title = "CLI Parser") const;
private: private:
void addArg (const std::string&); void addArg (const std::string&, Lexer::Type type = Lexer::Type::word);
void aliasExpansion (); void aliasExpansion ();
void findOverrides (); void findOverrides ();
void categorize (); void categorize ();

View file

@ -82,7 +82,7 @@ int CmdCustom::execute (std::string& output)
validateSortColumns (sortOrder); validateSortColumns (sortOrder);
// Prepend the argument list with those from the report filter. // Prepend the argument list with those from the report filter.
context.cli.addRawFilter(reportFilter); context.cli.addRawFilter (reportFilter);
// Apply filter. // Apply filter.
handleRecurrence (); handleRecurrence ();