From 84b305569062b2f469159dea1d1d4c300deb2adc Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 12 Sep 2015 09:03:15 -0400 Subject: [PATCH] CLI2: Pseudo-args demoted to config settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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. --- src/CLI2.cpp | 34 +++++++++++++++++++--------------- src/CLI2.h | 1 - src/Context.cpp | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/CLI2.cpp b/src/CLI2.cpp index c31f2b742..b9adc20b0 100644 --- a/src/CLI2.cpp +++ b/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 { diff --git a/src/CLI2.h b/src/CLI2.h index 854fb775d..2fb2fe9fd 100644 --- a/src/CLI2.h +++ b/src/CLI2.h @@ -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: diff --git a/src/Context.cpp b/src/Context.cpp index eead28b77..87bb280d0 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -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")