From cd8f7ddac4c8888a03798316e3a8a85961683a10 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 19 Oct 2014 17:59:51 -0400 Subject: [PATCH] CLI - Can now safely re-analyze command line if something changes. This required a ::analzye method to be called late in Context::initialize. --- src/CLI.cpp | 35 +++++++++++++---------------------- src/CLI.h | 1 + src/Context.cpp | 1 + 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index 235503a56..55851c06a 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -230,30 +230,10 @@ void CLI::initialize (int argc, const char** argv) { // Clean what needs to be cleaned. Everything in this case. _original_args.clear (); - _args.clear (); - for (int i = 0; i < argc; ++i) - { _original_args.push_back (argv[i]); - if (i == 0) - { - A a ("arg", argv[i]); - a.tag ("ORIGINAL"); - a.tag ("BINARY"); - _args.push_back (a); - } - else - { - A a ("arg", argv[i]); - a.tag ("ORIGINAL"); - _args.push_back (a); - } - } - - aliasExpansion (); - findOverrides (); - categorize (); + analyze (); } //////////////////////////////////////////////////////////////////////////////// @@ -261,9 +241,20 @@ void CLI::initialize (int argc, const char** argv) void CLI::add (const std::string& arg) { // Clean what needs to be cleaned. Most in this case. - _args.clear (); _original_args.push_back (arg); + analyze (); +} + +//////////////////////////////////////////////////////////////////////////////// +// Intended to be called after ::initialize() and ::add(), to perform the final +// analysis. Analysis is also performed directly after the above, because there +// is a need to extract overrides early, before entities are proviedd. +void CLI::analyze () +{ + // Clean what needs to be cleaned. Most in this case. + _args.clear (); + for (int i = 0; i < _original_args.size (); ++i) { if (i == 0) diff --git a/src/CLI.h b/src/CLI.h index fafe74d29..99546668e 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -66,6 +66,7 @@ public: void entity (const std::string&, const std::string&); void initialize (int, const char**); void add (const std::string&); + void analyze (); const std::string getFilter (); const std::vector getWords (); const std::vector getModifications (); diff --git a/src/Context.cpp b/src/Context.cpp index ad21ccf82..1cc1ebc88 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -248,6 +248,7 @@ int Context::initialize (int argc, const char** argv) staticInitialization (); // Decouple code from Context. parser.parse (); // Parse all elements. + cli.analyze (); // Parse all elements. tdb2.set_location (data_dir); // Prepare the task database.