diff --git a/src/CLI.cpp b/src/CLI.cpp index 240a07d9f..afcbefdb1 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -374,6 +374,50 @@ void CLI::add (const std::string& arg) analyze (); } +//////////////////////////////////////////////////////////////////////////////// +void CLI::addContextFilter () +{ + // Detect if any context is set, and bail out if not + std::string contextName = context.config.get ("context"); + + if (contextName == "") + { + context.debug("No context applied."); + return; + } + + // Detect if UUID or ID is set, and bail out + if (_args.size ()) + { + std::vector ::const_iterator a; + for (a = _args.begin (); a != _args.end (); ++a) + { + if (a->hasTag ("FILTER") && + a->hasTag ("ATTRIBUTE") && + ! a->hasTag ("TERMINATED") && + ! a->hasTag ("WORD") && + (a->attribute ("raw") == "id" || a->attribute ("raw") == "uuid")) + { + context.debug(format("UUID/ID lexeme found '{1}', not applying context.", a->attribute ("raw"))); + return; + } + } + } + + // Apply context + context.debug("Applying context: " + contextName); + std::string contextFilter = context.config.get ("context." + contextName); + + if (contextFilter == "") + context.debug("Context '" + contextName + "' not defined!"); + else + { + addRawFilter("( " + contextFilter + " )"); + if (context.verbose ("context")) + context.footnote (format("Context '{1}' applied.", contextName)); + } +} + //////////////////////////////////////////////////////////////////////////////// // Process raw string into parsed filter. // diff --git a/src/CLI.h b/src/CLI.h index c3aa0e692..634e05a91 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -77,6 +77,7 @@ public: void entity (const std::string&, const std::string&); void initialize (int, const char**); void add (const std::string&); + void addContextFilter (); void addRawFilter (const std::string& arg); void analyze (bool parse = true, bool strict = false); void applyOverrides ();