CLI2: Added ::getWords and ::getCommand variations

- ::getWords (false) now returns an unfiltered list of command line args,
  specifically any rc.<name>:<value> or rc:<file> args are left uninterpreted.
- ::getCommand (false) now returns the raw command, not the canonical command.
This commit is contained in:
Paul Beckingham 2015-06-17 04:14:37 -04:00
parent cbf20217dc
commit 12825c5205
2 changed files with 13 additions and 21 deletions

View file

@ -680,11 +680,11 @@ const std::string CLI2::getFilter (bool applyContext)
// - RC
// - CONFIG
// - --
const std::vector <std::string> CLI2::getWords ()
const std::vector <std::string> CLI2::getWords (bool filtered)
{
auto binary = getBinary ();
auto command = getCommand ();
auto commandRaw = getCommandRaw ();
auto commandRaw = getCommand (false);
std::vector <std::string> words;
for (auto& a : _original_args)
@ -692,11 +692,14 @@ const std::vector <std::string> 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 "";
}

View file

@ -94,11 +94,10 @@ public:
void applyOverrides ();
const std::string getFilter (bool applyContext = true);
*/
const std::vector <std::string> getWords ();
const std::vector <std::string> 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;
*/