CLI: Add addContextFilter method
This commit is contained in:
committed by
Paul Beckingham
parent
1abda3900b
commit
3a77a5f291
44
src/CLI.cpp
44
src/CLI.cpp
@@ -374,6 +374,50 @@ void CLI::add (const std::string& arg)
|
|||||||
analyze ();
|
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 <A>::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.
|
// Process raw string into parsed filter.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ public:
|
|||||||
void entity (const std::string&, const std::string&);
|
void entity (const std::string&, const std::string&);
|
||||||
void initialize (int, const char**);
|
void initialize (int, const char**);
|
||||||
void add (const std::string&);
|
void add (const std::string&);
|
||||||
|
void addContextFilter ();
|
||||||
void addRawFilter (const std::string& arg);
|
void addRawFilter (const std::string& arg);
|
||||||
void analyze (bool parse = true, bool strict = false);
|
void analyze (bool parse = true, bool strict = false);
|
||||||
void applyOverrides ();
|
void applyOverrides ();
|
||||||
|
|||||||
Reference in New Issue
Block a user