mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
CLI2: Refactored some of ::prepareFilter into ::categorizeArgs
This commit is contained in:
parent
5cd1649db2
commit
a82927cb54
2 changed files with 67 additions and 60 deletions
126
src/CLI2.cpp
126
src/CLI2.cpp
|
@ -620,66 +620,8 @@ void CLI2::prepareFilter ()
|
|||
_id_ranges.clear ();
|
||||
_uuid_list.clear ();
|
||||
|
||||
// Context is only applied for commands that request it.
|
||||
std::string command = getCommand ();
|
||||
Command* cmd = context.commands[command];
|
||||
if (cmd && cmd->uses_context ())
|
||||
addContextFilter ();
|
||||
|
||||
// Classify FILTER, MODIFICATION and MISCELLANEOUS args, based on CMD DNA.
|
||||
bool changes = false;
|
||||
bool afterCommand = false;
|
||||
|
||||
for (auto& a : _args)
|
||||
{
|
||||
if (a._lextype == Lexer::Type::separator)
|
||||
continue;
|
||||
|
||||
if (a.hasTag ("CMD"))
|
||||
{
|
||||
afterCommand = true;
|
||||
}
|
||||
else if (a.hasTag ("BINARY") ||
|
||||
a.hasTag ("RC") ||
|
||||
a.hasTag ("CONFIG"))
|
||||
{
|
||||
// NOP.
|
||||
}
|
||||
|
||||
// All MODIFICATION args appear after the command.
|
||||
else if (cmd &&
|
||||
cmd->accepts_modifications () &&
|
||||
! cmd->accepts_miscellaneous () &&
|
||||
afterCommand)
|
||||
{
|
||||
a.tag ("MODIFICATION");
|
||||
changes = true;
|
||||
}
|
||||
|
||||
else if (cmd &&
|
||||
cmd->accepts_miscellaneous () &&
|
||||
! cmd->accepts_modifications () &&
|
||||
(afterCommand ||
|
||||
! cmd->accepts_filter ()))
|
||||
{
|
||||
a.tag ("MISCELLANEOUS");
|
||||
changes = true;
|
||||
}
|
||||
|
||||
else if (cmd &&
|
||||
cmd->accepts_filter () &&
|
||||
(! afterCommand ||
|
||||
(! cmd->accepts_modifications () &&
|
||||
! cmd->accepts_miscellaneous ())))
|
||||
{
|
||||
a.tag ("FILTER");
|
||||
changes = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changes &&
|
||||
context.config.getInteger ("debug.parser") >= 3)
|
||||
context.debug (dump ("CLI2::prepareFilter"));
|
||||
// Determine arg types: FILTER, MODIFICATION, MISCELLANEOUS.
|
||||
categorizeArgs ();
|
||||
|
||||
// Remove all the syntactic sugar for FILTERs.
|
||||
lexFilterArgs ();
|
||||
|
@ -964,6 +906,70 @@ void CLI2::canonicalizeNames ()
|
|||
context.debug (dump ("CLI2::analyze canonicalizeNames"));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Categorize FILTER, MODIFICATION and MISCELLANEOUS args, based on CMD DNA.
|
||||
void CLI2::categorizeArgs ()
|
||||
{
|
||||
// Context is only applied for commands that request it.
|
||||
std::string command = getCommand ();
|
||||
Command* cmd = context.commands[command];
|
||||
if (cmd && cmd->uses_context ())
|
||||
addContextFilter ();
|
||||
|
||||
bool changes = false;
|
||||
bool afterCommand = false;
|
||||
for (auto& a : _args)
|
||||
{
|
||||
if (a._lextype == Lexer::Type::separator)
|
||||
continue;
|
||||
|
||||
if (a.hasTag ("CMD"))
|
||||
{
|
||||
afterCommand = true;
|
||||
}
|
||||
else if (a.hasTag ("BINARY") ||
|
||||
a.hasTag ("RC") ||
|
||||
a.hasTag ("CONFIG"))
|
||||
{
|
||||
// NOP.
|
||||
}
|
||||
|
||||
// All MODIFICATION args appear after the command.
|
||||
else if (cmd &&
|
||||
cmd->accepts_modifications () &&
|
||||
! cmd->accepts_miscellaneous () &&
|
||||
afterCommand)
|
||||
{
|
||||
a.tag ("MODIFICATION");
|
||||
changes = true;
|
||||
}
|
||||
|
||||
else if (cmd &&
|
||||
cmd->accepts_miscellaneous () &&
|
||||
! cmd->accepts_modifications () &&
|
||||
(afterCommand ||
|
||||
! cmd->accepts_filter ()))
|
||||
{
|
||||
a.tag ("MISCELLANEOUS");
|
||||
changes = true;
|
||||
}
|
||||
|
||||
else if (cmd &&
|
||||
cmd->accepts_filter () &&
|
||||
(! afterCommand ||
|
||||
(! cmd->accepts_modifications () &&
|
||||
! cmd->accepts_miscellaneous ())))
|
||||
{
|
||||
a.tag ("FILTER");
|
||||
changes = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changes &&
|
||||
context.config.getInteger ("debug.parser") >= 3)
|
||||
context.debug (dump ("CLI2::analyze categorizeArgs"));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Scan all arguments and if any are an exact match for a command name, then
|
||||
// tag as CMD. If an argument is an exact match for an attribute, despite being
|
||||
|
|
|
@ -90,6 +90,7 @@ private:
|
|||
void demotion ();
|
||||
void aliasExpansion ();
|
||||
void canonicalizeNames ();
|
||||
void categorizeArgs ();
|
||||
bool findCommand ();
|
||||
bool exactMatch (const std::string&, const std::string&) const;
|
||||
void desugarFilterTags ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue