CLI2: Prevent loops

- Context was sometimes causing looping:

    ::analyze -> ::addContexFilter -> ::addFilter -> ::analyze

  This is prevented by a simple latch.
This commit is contained in:
Paul Beckingham 2015-09-06 01:42:30 -04:00
parent 7da3f3b2ba
commit 3897c23c8d
2 changed files with 8 additions and 0 deletions

View file

@ -328,6 +328,7 @@ void CLI2::applyOverrides (int argc, const char** argv)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CLI2::CLI2 () CLI2::CLI2 ()
: _context_filter_added (false)
{ {
} }
@ -579,6 +580,10 @@ void CLI2::addFilter (const std::string& arg)
// - filter contains ID or UUID // - filter contains ID or UUID
void CLI2::addContextFilter () void CLI2::addContextFilter ()
{ {
// Recursion block.
if (_context_filter_added)
return;
// Detect if any context is set, and bail out if not // Detect if any context is set, and bail out if not
std::string contextName = context.config.get ("context"); std::string contextName = context.config.get ("context");
if (contextName == "") if (contextName == "")
@ -607,6 +612,7 @@ void CLI2::addContextFilter ()
context.debug ("Context '" + contextName + "' not defined."); context.debug ("Context '" + contextName + "' not defined.");
else else
{ {
_context_filter_added = true;
addFilter (contextFilter); addFilter (contextFilter);
if (context.verbose ("context")) if (context.verbose ("context"))
context.footnote (format ("Context '{1}' set. Use 'task context none' to remove.", contextName)); context.footnote (format ("Context '{1}' set. Use 'task context none' to remove.", contextName));
@ -621,6 +627,7 @@ void CLI2::prepareFilter ()
// Clear and re-populate. // Clear and re-populate.
_id_ranges.clear (); _id_ranges.clear ();
_uuid_list.clear (); _uuid_list.clear ();
_context_filter_added = false;
// Remove all the syntactic sugar for FILTERs. // Remove all the syntactic sugar for FILTERs.
lexFilterArgs (); lexFilterArgs ();

View file

@ -114,6 +114,7 @@ public:
std::vector <std::pair <std::string, std::string>> _id_ranges; std::vector <std::pair <std::string, std::string>> _id_ranges;
std::vector <std::string> _uuid_list; std::vector <std::string> _uuid_list;
bool _context_filter_added;
}; };
#endif #endif