mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 19:03:07 +02:00
CLI: Add addContextFilter method
This commit is contained in:
parent
1abda3900b
commit
3a77a5f291
2 changed files with 45 additions and 0 deletions
44
src/CLI.cpp
44
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 <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.
|
||||
//
|
||||
|
|
|
@ -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 ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue