From d6e11761a61c6582cd7b47397f669d2e67f63179 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 14 Oct 2014 23:26:12 -0400 Subject: [PATCH] CLI - Added diagnostics only to ::initialize and ::add. - Now properly clears and regenerates all data on change. --- src/CLI.cpp | 40 ++++++++++++++++++++++++++++------------ src/CLI.h | 9 ++++----- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index 54106d129..e76048db1 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -71,25 +71,48 @@ void CLI::entity (const std::string& name, const std::string& value) // Capture the original, intact command line arguments. void CLI::initialize (int argc, const char** argv) { + // Clean what needs to be cleaned. Everything in this case. + _program = ""; + _original_args.clear (); + _args.clear (); + _rc = ""; + _overrides.clear (); + _command = ""; + _readOnly = false; + _filter.clear (); + _modifications.clear (); + _program = argv[0]; for (int i = 1; i < argc; ++i) _original_args.push_back (argv[i]); _args = _original_args; - dump ("CLI::initialize"); + aliasExpansion (); extractOverrides (); + categorize (); + + dump ("CLI::initialize"); } //////////////////////////////////////////////////////////////////////////////// void CLI::add (const std::string& arg) { - _original_args.push_back (arg); - _args.push_back (arg); + // Clean what needs to be cleaned. Most in this case. + _program = ""; + _args.clear (); + _rc = ""; + _overrides.clear (); + _command = ""; + _readOnly = false; + _filter.clear (); + _modifications.clear (); + + _original_args.push_back (arg); + _args = _original_args; - dump ("CLI::add"); - extractOverrides (); aliasExpansion (); + extractOverrides (); categorize (); dump ("CLI::add"); @@ -160,11 +183,6 @@ void CLI::categorize () { bool foundCommand = false; - _filter.clear (); - _modifications.clear (); - _command = ""; - _readOnly = false; - std::vector ::iterator i; for (i = _args.begin (); i != _args.end (); ++i) { @@ -182,8 +200,6 @@ void CLI::categorize () _filter.push_back (*i); } } - - dump ("CLI::categorize"); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CLI.h b/src/CLI.h index 78bdb17e5..c41d81fea 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -39,16 +39,16 @@ public: void entity (const std::string&, const std::string&); void initialize (int, const char**); void add (const std::string&); - void aliasExpansion (); - void categorize (); - bool exactMatch (const std::string&, const std::string&) const; - bool canonicalize (std::string&, const std::string&, const std::string&) const; const std::string getFilter () const; const std::vector getWords () const; const std::vector getModifications () const; private: + void aliasExpansion (); void extractOverrides (); + void categorize (); + bool exactMatch (const std::string&, const std::string&) const; + bool canonicalize (std::string&, const std::string&, const std::string&) const; void dump (const std::string&) const; public: @@ -59,7 +59,6 @@ public: std::vector _args; std::string _rc; std::map _overrides; - std::string _command; bool _readOnly; std::vector _filter;