- Implemented ::injectDefaults for rc.default.command and auto info.
This commit is contained in:
Paul Beckingham
2014-11-02 23:30:59 -05:00
parent 086f7ec684
commit 6ccec121c9

View File

@@ -337,6 +337,7 @@ void CLI::analyze (bool parse /* = true */)
// Find argument types. // Find argument types.
aliasExpansion (); aliasExpansion ();
injectDefaults ();
findOverrides (); findOverrides ();
categorize (); categorize ();
@@ -349,7 +350,6 @@ void CLI::analyze (bool parse /* = true */)
desugarPatterns (); desugarPatterns ();
findIDs (); findIDs ();
findUUIDs (); findUUIDs ();
injectDefaults ();
insertIDExpr (); insertIDExpr ();
findOperators (); findOperators ();
findAttributes (); findAttributes ();
@@ -1725,20 +1725,21 @@ void CLI::injectDefaults ()
std::vector <A>::iterator a; std::vector <A>::iterator a;
for (a = _args.begin (); a != _args.end (); ++a) for (a = _args.begin (); a != _args.end (); ++a)
{ {
if (a->hasTag ("TERMINATOR")) std::string raw = a->attribute ("raw");
if (isTerminator (raw))
found_terminator = true; found_terminator = true;
if (! found_terminator && a->hasTag ("CMD")) if (! found_terminator && isCommand (raw))
found_command = true; found_command = true;
else if (! found_terminator && (a->hasTag ("ID") || a->hasTag ("UUID"))) else if (! found_terminator &&
(isUUIDList (raw) ||
isUUID (raw) ||
isIDSequence (raw) ||
isID (raw)))
found_sequence = true; found_sequence = true;
} }
// TODO Remove
context.debug (std::string ("CLI::injectDefaults found_command ") + (found_command ? "true" : "false"));
context.debug (std::string ("CLI::injectDefaults found_sequence ") + (found_sequence ? "true" : "false"));
// If no command was specified, then a command will be inserted. // If no command was specified, then a command will be inserted.
if (! found_command) if (! found_command)
{ {
@@ -1752,36 +1753,41 @@ void CLI::injectDefaults ()
if (context.config.getBoolean ("debug")) if (context.config.getBoolean ("debug"))
context.debug (std::string ("No command or sequence found - assuming default.command '") + defaultCommand + "'."); context.debug (std::string ("No command or sequence found - assuming default.command '") + defaultCommand + "'.");
/* // Split the defaultCommand into separate args.
// Split the defaultCommand into args, and add them in reverse order, std::vector <std::string> tokens;
// because captureFirst inserts args immediately after the command, and Lexer::token_split (tokens, defaultCommand);
// so has the effect of reversing the list.
std::vector <std::string> args; // Modify _args to be: <args0> [<def0> ...] <args1> [...]
split (args, defaultCommand, ' '); std::vector <A> reconstructed;
std::vector <std::string>::reverse_iterator r; for (a = _args.begin (); a != _args.end (); ++a)
for (r = args.rbegin (); r != args.rend (); ++r)
{ {
if (*r != "") reconstructed.push_back (*a);
if (a == _args.begin ())
{ {
Tree* t = captureFirst (*r); std::vector <std::string>::iterator t;
t->tag ("DEFAULT"); for (t = tokens.begin (); t != tokens.end (); ++t)
{
A arg ("argDefault", *t);
arg.tag ("DEFAULT");
reconstructed.push_back (arg);
}
} }
} }
_args = reconstructed;
// Extract a recomposed command line.
std::string combined; std::string combined;
std::vector <Tree*> nodes; for (a = _args.begin (); a != _args.end (); ++a)
collect (nodes, collectTerminated);
std::vector <Tree*>::iterator i;
for (i = nodes.begin (); i != nodes.end (); ++i)
{ {
if (combined.length ()) if (combined.length ())
combined += ' '; combined += ' ';
combined += (*i)->attribute ("raw"); combined += a->attribute ("raw");
} }
context.header ("[" + combined + "]"); context.header ("[" + combined + "]");
*/
} }
else else
{ {
@@ -1792,14 +1798,13 @@ void CLI::injectDefaults ()
} }
else else
{ {
/*
if (context.config.getBoolean ("debug")) if (context.config.getBoolean ("debug"))
context.debug ("Sequence but no command found - assuming 'information' command."); context.debug ("Sequence but no command found - assuming 'information' command.");
context.header (STRING_ASSUME_INFO); context.header (STRING_ASSUME_INFO);
Tree* t = captureFirst ("information"); A info ("argDefault", "information");
t->tag ("ASSUMED"); info.tag ("ASSUMED");
*/ _args.push_back (info);
} }
} }