CLI2: Added ::addContextFilter, and supporting processing
This commit is contained in:
94
src/CLI2.cpp
94
src/CLI2.cpp
@@ -414,51 +414,6 @@ void CLI2::analyze ()
|
|||||||
context.debug (dump ("CLI2::analyze end"));
|
context.debug (dump ("CLI2::analyze end"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// There are situations where a context filter is applied. This method
|
|
||||||
// determines whether one applies, and if so, applies it. Disqualifiers include:
|
|
||||||
// - filter contains ID or UUID
|
|
||||||
void CLI2::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
|
|
||||||
for (auto& a : _args)
|
|
||||||
{
|
|
||||||
// TODO This looks wrong.
|
|
||||||
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}' set. Use 'task context none' to remove.", contextName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Process raw string.
|
// Process raw string.
|
||||||
void CLI2::addFilter (const std::string& arg)
|
void CLI2::addFilter (const std::string& arg)
|
||||||
@@ -480,6 +435,52 @@ void CLI2::addFilter (const std::string& arg)
|
|||||||
analyze ();
|
analyze ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// There are situations where a context filter is applied. This method
|
||||||
|
// determines whether one applies, and if so, applies it. Disqualifiers include:
|
||||||
|
// - filter contains ID or UUID
|
||||||
|
void CLI2::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
|
||||||
|
for (auto& a : _args)
|
||||||
|
{
|
||||||
|
// TODO This is needed, but the parsing is not yet complete, so the logic
|
||||||
|
// below is not valid.
|
||||||
|
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
|
||||||
|
{
|
||||||
|
addFilter (contextFilter);
|
||||||
|
if (context.verbose ("context"))
|
||||||
|
context.footnote (format ("Context '{1}' set. Use 'task context none' to remove.", contextName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Parse the command line, identifiying filter components, expanding syntactic
|
// Parse the command line, identifiying filter components, expanding syntactic
|
||||||
// sugar as necessary.
|
// sugar as necessary.
|
||||||
@@ -489,6 +490,9 @@ void CLI2::prepareFilter (bool applyContext)
|
|||||||
_id_ranges.clear ();
|
_id_ranges.clear ();
|
||||||
_uuid_list.clear ();
|
_uuid_list.clear ();
|
||||||
|
|
||||||
|
if (applyContext)
|
||||||
|
addContextFilter ();
|
||||||
|
|
||||||
// Classify FILTER and MODIFICATION args, based on CMD and READCMD/WRITECMD.
|
// Classify FILTER and MODIFICATION args, based on CMD and READCMD/WRITECMD.
|
||||||
bool changes = false;
|
bool changes = false;
|
||||||
bool foundCommand = false;
|
bool foundCommand = false;
|
||||||
|
|||||||
@@ -73,10 +73,8 @@ public:
|
|||||||
|
|
||||||
void add (const std::string&);
|
void add (const std::string&);
|
||||||
void analyze ();
|
void analyze ();
|
||||||
/*
|
|
||||||
void addContextFilter ();
|
|
||||||
*/
|
|
||||||
void addFilter (const std::string& arg);
|
void addFilter (const std::string& arg);
|
||||||
|
void addContextFilter ();
|
||||||
void prepareFilter (bool applyContext = true);
|
void prepareFilter (bool applyContext = true);
|
||||||
const std::vector <std::string> getWords (bool filtered = true);
|
const std::vector <std::string> getWords (bool filtered = true);
|
||||||
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output
|
|||||||
context.timer_filter.start ();
|
context.timer_filter.start ();
|
||||||
_startCount = (int) input.size ();
|
_startCount = (int) input.size ();
|
||||||
|
|
||||||
// context.cli2.prepareFilter (applyContext);
|
context.cli2.prepareFilter (applyContext);
|
||||||
|
|
||||||
std::vector <std::pair <std::string, Lexer::Type>> precompiled;
|
std::vector <std::pair <std::string, Lexer::Type>> precompiled;
|
||||||
for (auto& a : context.cli2._args)
|
for (auto& a : context.cli2._args)
|
||||||
if (a.hasTag ("FILTER"))
|
if (a.hasTag ("FILTER"))
|
||||||
@@ -118,6 +119,8 @@ void Filter::subset (std::vector <Task>& output, bool applyContext /* = true */)
|
|||||||
{
|
{
|
||||||
context.timer_filter.start ();
|
context.timer_filter.start ();
|
||||||
|
|
||||||
|
context.cli2.prepareFilter (applyContext);
|
||||||
|
|
||||||
std::vector <std::pair <std::string, Lexer::Type>> precompiled;
|
std::vector <std::pair <std::string, Lexer::Type>> precompiled;
|
||||||
for (auto& a : context.cli2._args)
|
for (auto& a : context.cli2._args)
|
||||||
if (a.hasTag ("FILTER"))
|
if (a.hasTag ("FILTER"))
|
||||||
|
|||||||
@@ -81,10 +81,7 @@ int CmdCustom::execute (std::string& output)
|
|||||||
|
|
||||||
// Add the report filter to any existing filter.
|
// Add the report filter to any existing filter.
|
||||||
if (reportFilter != "")
|
if (reportFilter != "")
|
||||||
{
|
|
||||||
context.cli2.addFilter (reportFilter);
|
context.cli2.addFilter (reportFilter);
|
||||||
context.cli2.prepareFilter ();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply filter.
|
// Apply filter.
|
||||||
handleRecurrence ();
|
handleRecurrence ();
|
||||||
|
|||||||
Reference in New Issue
Block a user