CLI2: ADded ::findCommand.

This commit is contained in:
Paul Beckingham 2015-06-14 15:29:40 -04:00
parent 9d5a10bd89
commit cacc427cbd
2 changed files with 45 additions and 0 deletions

View file

@ -412,6 +412,7 @@ void CLI2::analyze ()
// Process _args. // Process _args.
aliasExpansion (); aliasExpansion ();
findOverrides (); findOverrides ();
findCommand ();
if (context.config.getInteger ("debug.parser") >= 3) if (context.config.getInteger ("debug.parser") >= 3)
{ {
@ -923,6 +924,49 @@ void CLI2::findOverrides ()
context.debug (dump ("CLI2::analyze findOverrides")); context.debug (dump ("CLI2::analyze findOverrides"));
} }
////////////////////////////////////////////////////////////////////////////////
void CLI2::findCommand ()
{
bool changes = false;
bool foundCommand = false;
bool readOnly = false;
bool terminated = false;
for (auto& a : _args)
{
std::string raw = a.attribute ("raw");
if (a._lextype == Lexer::Type::separator)
{
terminated = true;
}
else if (terminated)
{
a.tag ("WORD");
changes = true;
}
else
{
std::string canonical;
if (! foundCommand &&
canonicalize (canonical, "cmd", raw))
{
readOnly = ! exactMatch ("writecmd", canonical);
a.tag ("CMD");
a.tag (readOnly ? "READCMD" : "WRITECMD");
a.attribute ("canonical", canonical);
foundCommand = true;
changes = true;
}
}
}
if (changes &&
context.config.getInteger ("debug.parser") >= 3)
context.debug (dump ("CLI2::analyze findCommand"));
}
/* /*
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TODO This method should further categorize args into whether or not they are // TODO This method should further categorize args into whether or not they are

View file

@ -114,6 +114,7 @@ private:
void lexArguments (); void lexArguments ();
void aliasExpansion (); void aliasExpansion ();
void findOverrides (); void findOverrides ();
void findCommand ();
/* /*
void categorize (); void categorize ();
*/ */