CLI2: ::defaultCommand now expands both _args and _original_args

This commit is contained in:
Paul Beckingham 2015-06-16 21:39:51 -04:00
parent 9ea2702696
commit 40d019c249

View file

@ -1991,30 +1991,33 @@ void CLI2::defaultCommand ()
std::string defaultCommand = context.config.get ("default.command"); std::string defaultCommand = context.config.get ("default.command");
if (defaultCommand != "") if (defaultCommand != "")
{ {
// Modify _args to be: <args0> [<def0> ...] <args1> [...] // Modify _args, _original_args to be:
std::vector <A2> reconstructed; // <args0> [<def0> ...] <args1> [...]
for (auto a = _args.begin (); a != _args.end (); ++a)
std::vector <std::string> reconstructedOriginals {_original_args[0]};
std::vector <A2> reconstructed {_args[0]};
std::string lexeme;
Lexer::Type type;
Lexer lex (defaultCommand);
lex.ambiguity (false);
while (lex.token (lexeme, type))
{ {
// This stores the argument, and has the side effect of positioning reconstructedOriginals.push_back (lexeme);
// insertions *after* the CMD.
reconstructed.push_back (*a);
if (a == _args.begin ()) A2 cmd (lexeme, type);
{ cmd.tag ("DEFAULT");
std::string lexeme; reconstructed.push_back (cmd);
Lexer::Type type;
Lexer lex (defaultCommand);
lex.ambiguity (false);
while (lex.token (lexeme, type))
{
A2 cmd (lexeme, type);
cmd.tag ("DEFAULT");
reconstructed.push_back (cmd);
}
}
} }
for (unsigned int i = 1; i < _original_args.size (); ++i)
reconstructedOriginals.push_back (_original_args[i]);
for (unsigned int i = 1; i < _args.size (); ++i)
reconstructed.push_back (_args[i]);
_original_args = reconstructedOriginals;
_args = reconstructed; _args = reconstructed;
changes = true; changes = true;
} }