From 12825c5205f3c45e379b80a14db14761bb9bedb6 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 17 Jun 2015 04:14:37 -0400 Subject: [PATCH] CLI2: Added ::getWords and ::getCommand variations - ::getWords (false) now returns an unfiltered list of command line args, specifically any rc.: or rc: args are left uninterpreted. - ::getCommand (false) now returns the raw command, not the canonical command. --- src/CLI2.cpp | 29 +++++++++++------------------ src/CLI2.h | 5 ++--- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/CLI2.cpp b/src/CLI2.cpp index 4aeeb99b5..d0d7b01f5 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -680,11 +680,11 @@ const std::string CLI2::getFilter (bool applyContext) // - RC // - CONFIG // - -- -const std::vector CLI2::getWords () +const std::vector CLI2::getWords (bool filtered) { auto binary = getBinary (); auto command = getCommand (); - auto commandRaw = getCommandRaw (); + auto commandRaw = getCommand (false); std::vector words; for (auto& a : _original_args) @@ -692,11 +692,14 @@ const std::vector CLI2::getWords () if (a != binary && a != command && a != commandRaw && - a != "--" && - a.find ("rc:") != 0 && - a.find ("rc.") != 0) + a != "--") { - words.push_back (a); + if (! filtered || + (a.find ("rc:") != 0 && + a.find ("rc.") != 0)) + { + words.push_back (a); + } } } @@ -755,21 +758,11 @@ std::string CLI2::getBinary () const } //////////////////////////////////////////////////////////////////////////////// -std::string CLI2::getCommand () const +std::string CLI2::getCommand (bool canonical) const { for (auto& a : _args) if (a.hasTag ("CMD")) - return a.attribute ("canonical"); - - return ""; -} - -//////////////////////////////////////////////////////////////////////////////// -std::string CLI2::getCommandRaw () const -{ - for (auto& a : _args) - if (a.hasTag ("CMD")) - return a.attribute ("raw"); + return a.attribute (canonical ? "canonical" : "raw"); return ""; } diff --git a/src/CLI2.h b/src/CLI2.h index 985e4323e..935e6e71c 100644 --- a/src/CLI2.h +++ b/src/CLI2.h @@ -94,11 +94,10 @@ public: void applyOverrides (); const std::string getFilter (bool applyContext = true); */ - const std::vector getWords (); + const std::vector getWords (bool filtered = true); bool canonicalize (std::string&, const std::string&, const std::string&) const; std::string getBinary () const; - std::string getCommand () const; - std::string getCommandRaw () const; + std::string getCommand (bool canonical = true) const; /* std::string getLimit () const; */