- 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,7 +377,6 @@ 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.");
@@ -392,6 +389,7 @@ 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") &&
@@ -409,7 +407,7 @@ void CLI::addContextFilter ()
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 + " )");
@@ -420,7 +418,6 @@ void CLI::addContextFilter ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// 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 ();