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:
34
src/CLI2.cpp
34
src/CLI2.cpp
@@ -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
|
||||
{
|
||||
|
||||
@@ -81,7 +81,6 @@ public:
|
||||
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
||||
std::string getBinary () const;
|
||||
std::string getCommand (bool canonical = true) const;
|
||||
std::string getLimit () const;
|
||||
const std::string dump (const std::string& title = "CLI2 Parser") const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -595,7 +595,7 @@ void Context::getLimits (int& rows, int& lines)
|
||||
lines = 0;
|
||||
|
||||
// This is an integer specified as a filter (limit:10).
|
||||
std::string limit = cli2.getLimit ();
|
||||
std::string limit = config.get ("limit");
|
||||
if (limit != "")
|
||||
{
|
||||
if (limit == "page")
|
||||
|
||||
Reference in New Issue
Block a user