mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CLI: Added ::canonicalizeNames for commands and keywords
This commit is contained in:
parent
27f13f84ed
commit
c2a10e6848
2 changed files with 41 additions and 0 deletions
40
src/CLI.cpp
40
src/CLI.cpp
|
@ -224,6 +224,7 @@ void CLI::analyze ()
|
||||||
handleArg0 ();
|
handleArg0 ();
|
||||||
lexArguments ();
|
lexArguments ();
|
||||||
findCommand ();
|
findCommand ();
|
||||||
|
canonicalizeNames ();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -288,6 +289,45 @@ const std::string CLI::dump (const std::string& title) const
|
||||||
return out.str ();
|
return out.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Scan all arguments and canonicalize names that need it.
|
||||||
|
void CLI::canonicalizeNames ()
|
||||||
|
{
|
||||||
|
for (auto& a : _args)
|
||||||
|
{
|
||||||
|
auto raw = a.attribute ("raw");
|
||||||
|
std::string canonical;
|
||||||
|
|
||||||
|
// Commands.
|
||||||
|
if (exactMatch ("command", raw))
|
||||||
|
{
|
||||||
|
a.attribute ("canonical", raw);
|
||||||
|
a.tag ("CMD");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (canonicalize (canonical, "command", raw))
|
||||||
|
{
|
||||||
|
a.attribute ("canonical", canonical);
|
||||||
|
a.tag ("CMD");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commands.
|
||||||
|
if (exactMatch ("keyword", raw))
|
||||||
|
{
|
||||||
|
a.attribute ("canonical", raw);
|
||||||
|
a.tag ("KEYWORD");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (canonicalize (canonical, "keyword", raw))
|
||||||
|
{
|
||||||
|
a.attribute ("keyword", canonical);
|
||||||
|
a.tag ("KEYWORD");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Scan all arguments and if any are an exact match for a command name, then
|
// 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
|
// tag as CMD. If an argument is an exact match for an attribute, despite being
|
||||||
|
|
|
@ -65,6 +65,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void handleArg0 ();
|
void handleArg0 ();
|
||||||
void lexArguments ();
|
void lexArguments ();
|
||||||
|
void canonicalizeNames ();
|
||||||
bool findCommand ();
|
bool findCommand ();
|
||||||
bool exactMatch (const std::string&, const std::string&) const;
|
bool exactMatch (const std::string&, const std::string&) const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue