CLI2: Pseudo-args demoted to config settings

- When 'limit:N' is encountered, it is removed from the command line, and
  added as a config setting, equivalent to 'rc.limit:N'.
- This simplifieѕ subsequent command line parsing.
This commit is contained in:
Paul Beckingham 2015-09-12 09:03:15 -04:00
parent c59afe34c4
commit 84b3055690
3 changed files with 20 additions and 17 deletions

View file

@ -506,10 +506,9 @@ void CLI2::lexArguments ()
}
////////////////////////////////////////////////////////////////////////////////
// Scan all args for the 'add' and 'log' commands, and demote any
// Lexer::Type::Tag args with sign '-' to Lexer::Type::word.
//
// TODO This is obsolete, given FILTER, MODIFICATION, MISCELLANEOUS.
// [1] Scan all args for the 'add' and 'log' commands, and demote any
// Lexer::Type::Tag args with sign '-' to Lexer::Type::word.
// [2] Convert any pseudo args name:value into config settings, and erase.
void CLI2::demotion ()
{
bool changes = false;
@ -529,6 +528,22 @@ void CLI2::demotion ()
}
}
int count = 0;
for (auto& a : _args)
{
std::string canonical;
if (a._lextype == Lexer::Type::pair &&
canonicalize (canonical, "pseudo", a.attribute ("name")))
{
context.config.set (canonical, a.attribute ("value"));
changes = true;
_args.erase (_args.begin () + count);
break;
}
++count;
}
if (changes &&
context.config.getInteger ("debug.parser") >= 2)
context.debug (dump ("CLI2::analyze demotion"));
@ -726,17 +741,6 @@ std::string CLI2::getCommand (bool canonical) const
return "";
}
////////////////////////////////////////////////////////////////////////////////
std::string CLI2::getLimit () const
{
for (auto& a : _args)
if (a.hasTag ("PSEUDO") &&
a.attribute ("canonical") == "limit")
return a.attribute ("value");
return "0";
}
////////////////////////////////////////////////////////////////////////////////
const std::string CLI2::dump (const std::string& title) const
{