From b9b998c7694db85f7e957db9959645afc39a5067 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 8 Nov 2014 14:00:39 -0500 Subject: [PATCH] CLI - Added a strict analysis mode that throws errors. In non-strict mode no errors are thrown because parsing is incomplete most of the time, and only the final pass needs to be strict. --- src/CLI.cpp | 13 +++++++------ src/CLI.h | 3 ++- src/Context.cpp | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index 1c29c09aa..0f72f8a67 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -219,6 +219,7 @@ const std::string A::dump () const //////////////////////////////////////////////////////////////////////////////// CLI::CLI () +: _strict (false) { } @@ -283,13 +284,16 @@ void CLI::add (const std::string& arg) // 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 (bool parse /* = true */) +void CLI::analyze (bool parse /* = true */, bool strict /* = false */) { // Clean what needs to be cleaned. Most in this case. _args.clear (); _id_ranges.clear (); _uuid_list.clear (); + // For propagation. + _strict = strict; + for (int i = 0; i < _original_args.size (); ++i) { if (i == 0) @@ -1785,13 +1789,10 @@ void CLI::injectDefaults () context.header ("[" + combined + "]"); } - // TODO This fails because when ::injectDefaults is first run, - // ::applyOverrides has not yet been called. - else + // Only an error in strict mode. + else if (_strict) { -/* throw std::string (STRING_TRIVIAL_INPUT); -*/ } } else diff --git a/src/CLI.h b/src/CLI.h index 985d63fe6..20df68978 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -73,7 +73,7 @@ public: void entity (const std::string&, const std::string&); void initialize (int, const char**); void add (const std::string&); - void analyze (bool parse = true); + void analyze (bool parse = true, bool strict = false); void applyOverrides (); void getOverride (std::string&, File&); void getDataLocation (Path&); @@ -132,6 +132,7 @@ public: std::vector > _id_ranges; std::vector _uuid_list; + bool _strict; }; #endif diff --git a/src/Context.cpp b/src/Context.cpp index 515a899c7..76ab6e172 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -209,7 +209,7 @@ int Context::initialize (int argc, const char** argv) cli.entity ("attribute", col->first); staticInitialization (); // Decouple code from Context. - cli.analyze (); // Parse all elements. + cli.analyze (true, true); // Parse all elements, strict mode. tdb2.set_location (data_dir); // Prepare the task database.