From 40d019c2498d7dcadfb5d3b538427ccb22f2ce74 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 16 Jun 2015 21:39:51 -0400 Subject: [PATCH] CLI2: ::defaultCommand now expands both _args and _original_args --- src/CLI2.cpp | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/CLI2.cpp b/src/CLI2.cpp index 19d5cdab7..4aeeb99b5 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -1991,30 +1991,33 @@ void CLI2::defaultCommand () std::string defaultCommand = context.config.get ("default.command"); if (defaultCommand != "") { - // Modify _args to be: [ ...] [...] - std::vector reconstructed; - for (auto a = _args.begin (); a != _args.end (); ++a) + // Modify _args, _original_args to be: + // [ ...] [...] + + std::vector reconstructedOriginals {_original_args[0]}; + std::vector 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 - // insertions *after* the CMD. - reconstructed.push_back (*a); + reconstructedOriginals.push_back (lexeme); - if (a == _args.begin ()) - { - std::string lexeme; - 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); - } - } + 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; changes = true; }