CLI2: When applying extra filters, insert at the beginning, thus avoiding '--'

This commit is contained in:
Paul Beckingham 2015-08-02 10:20:12 -04:00
parent 1921ed77d5
commit 941e8c9f37
2 changed files with 26 additions and 3 deletions

View file

@ -364,6 +364,25 @@ void CLI2::add (const std::string& argument)
_args.clear (); _args.clear ();
} }
////////////////////////////////////////////////////////////////////////////////
// Capture a set of arguments, inserted immediately after the binary.
void CLI2::add (const std::vector <std::string>& arguments)
{
std::vector <std::string> replacement;
replacement.push_back (_original_args[0]);
for (auto& arg : arguments)
replacement.push_back (arg);
for (unsigned int i = 1; i < _original_args.size (); ++i)
replacement.push_back (_original_args[i]);
_original_args = replacement;
// Adding a new argument invalidates prior analysis.
_args.clear ();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Arg0 is the first argument, which is the name and potentially a relative or // Arg0 is the first argument, which is the name and potentially a relative or
// absolute path to the invoked binary. // absolute path to the invoked binary.
@ -532,19 +551,22 @@ void CLI2::analyze ()
// Process raw string. // Process raw string.
void CLI2::addFilter (const std::string& arg) void CLI2::addFilter (const std::string& arg)
{ {
std::vector <std::string> filter;
if (arg.length ()) if (arg.length ())
add ("("); filter.push_back ("(");
std::string lexeme; std::string lexeme;
Lexer::Type type; Lexer::Type type;
Lexer lex (arg); Lexer lex (arg);
while (lex.token (lexeme, type)) while (lex.token (lexeme, type))
add (lexeme); filter.push_back (lexeme);
if (arg.length ()) if (arg.length ())
add (")"); filter.push_back (")");
add (filter);
analyze (); analyze ();
} }

View file

@ -74,6 +74,7 @@ public:
void entity (const std::string&, const std::string&); void entity (const std::string&, const std::string&);
void add (const std::string&); void add (const std::string&);
void add (const std::vector <std::string>&);
void analyze (); void analyze ();
void addFilter (const std::string& arg); void addFilter (const std::string& arg);
void addContextFilter (); void addContextFilter ();