CLI2: Added ::addContextFilter, and supporting processing

This commit is contained in:
Paul Beckingham 2015-06-27 15:53:24 -04:00
parent 7425c8f2ae
commit b67b2ccc96
4 changed files with 54 additions and 52 deletions

View file

@ -414,51 +414,6 @@ void CLI2::analyze ()
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.
void CLI2::addFilter (const std::string& arg)
@ -480,6 +435,52 @@ void CLI2::addFilter (const std::string& arg)
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
// sugar as necessary.
@ -489,6 +490,9 @@ void CLI2::prepareFilter (bool applyContext)
_id_ranges.clear ();
_uuid_list.clear ();
if (applyContext)
addContextFilter ();
// Classify FILTER and MODIFICATION args, based on CMD and READCMD/WRITECMD.
bool changes = false;
bool foundCommand = false;