mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CLI: Added ::findCommand
This commit is contained in:
parent
8180104d45
commit
af5ee87773
2 changed files with 34 additions and 0 deletions
33
src/CLI.cpp
33
src/CLI.cpp
|
@ -221,6 +221,7 @@ void CLI::analyze ()
|
|||
_args.clear ();
|
||||
handleArg0 ();
|
||||
lexArguments ();
|
||||
findCommand ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -285,6 +286,38 @@ const std::string CLI::dump (const std::string& title) const
|
|||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
// an inexact match for a command, then it is not a command.
|
||||
bool CLI::findCommand ()
|
||||
{
|
||||
for (auto& a : _args)
|
||||
{
|
||||
auto raw = a.attribute ("raw");
|
||||
std::string canonical;
|
||||
|
||||
// If the arg canonicalized to a 'cmd', but is also not an exact match
|
||||
// for an 'attribute', proceed. Example:
|
||||
// task project=foo list
|
||||
// ^cmd ^cmd
|
||||
// ^attribute
|
||||
if (exactMatch ("command", raw))
|
||||
canonical = raw;
|
||||
else if (! canonicalize (canonical, "command", raw))
|
||||
continue;
|
||||
|
||||
a.attribute ("canonical", canonical);
|
||||
a.tag ("CMD");
|
||||
|
||||
// Stop and indicate command found.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Indicate command not found.
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Search for exact 'value' in _entities category.
|
||||
bool CLI::exactMatch (
|
||||
|
|
|
@ -65,6 +65,7 @@ public:
|
|||
private:
|
||||
void handleArg0 ();
|
||||
void lexArguments ();
|
||||
bool findCommand ();
|
||||
bool exactMatch (const std::string&, const std::string&) const;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue