diff --git a/src/CLI2.cpp b/src/CLI2.cpp index 1b4cc7b03..b9abfa696 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -412,6 +412,7 @@ void CLI2::analyze () // Process _args. aliasExpansion (); findOverrides (); + findCommand (); if (context.config.getInteger ("debug.parser") >= 3) { @@ -923,6 +924,49 @@ void CLI2::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 diff --git a/src/CLI2.h b/src/CLI2.h index c184d9735..cc2b203df 100644 --- a/src/CLI2.h +++ b/src/CLI2.h @@ -114,6 +114,7 @@ private: void lexArguments (); void aliasExpansion (); void findOverrides (); + void findCommand (); /* void categorize (); */