mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CLI: Added support for config overrides inthe parser
This commit is contained in:
parent
dfdb8c799a
commit
20a77c7d53
2 changed files with 31 additions and 2 deletions
28
src/CLI.cpp
28
src/CLI.cpp
|
@ -110,6 +110,7 @@ std::string A2::dump () const
|
||||||
else if (tag == "EXT") tags += "\033[1;37;42m" + tag + "\033[0m ";
|
else if (tag == "EXT") tags += "\033[1;37;42m" + tag + "\033[0m ";
|
||||||
else if (tag == "HINT") tags += "\033[1;37;43m" + tag + "\033[0m ";
|
else if (tag == "HINT") tags += "\033[1;37;43m" + tag + "\033[0m ";
|
||||||
else if (tag == "FILTER") tags += "\033[1;37;45m" + tag + "\033[0m ";
|
else if (tag == "FILTER") tags += "\033[1;37;45m" + tag + "\033[0m ";
|
||||||
|
else if (tag == "CONFIG") tags += "\033[1;37;101m" + tag + "\033[0m ";
|
||||||
else tags += "\033[32m" + tag + "\033[0m ";
|
else tags += "\033[32m" + tag + "\033[0m ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +250,7 @@ void CLI::analyze ()
|
||||||
_args.clear ();
|
_args.clear ();
|
||||||
handleArg0 ();
|
handleArg0 ();
|
||||||
lexArguments ();
|
lexArguments ();
|
||||||
|
identifyOverrides ();
|
||||||
canonicalizeNames ();
|
canonicalizeNames ();
|
||||||
identifyFilter ();
|
identifyFilter ();
|
||||||
}
|
}
|
||||||
|
@ -261,6 +263,7 @@ std::vector <std::string> CLI::getWords () const
|
||||||
for (auto& a : _args)
|
for (auto& a : _args)
|
||||||
if (! a.hasTag ("BINARY") &&
|
if (! a.hasTag ("BINARY") &&
|
||||||
! a.hasTag ("CMD") &&
|
! a.hasTag ("CMD") &&
|
||||||
|
! a.hasTag ("CONFIG") &&
|
||||||
! a.hasTag ("HINT"))
|
! a.hasTag ("HINT"))
|
||||||
words.push_back (a.attribute ("raw"));
|
words.push_back (a.attribute ("raw"));
|
||||||
|
|
||||||
|
@ -352,6 +355,30 @@ std::string CLI::dump (const std::string& title) const
|
||||||
return out.str ();
|
return out.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Scan all arguments and identify instances of 'rc.<name>[:=]<value>'.
|
||||||
|
void CLI::identifyOverrides ()
|
||||||
|
{
|
||||||
|
for (auto& a : _args)
|
||||||
|
{
|
||||||
|
auto raw = a.attribute ("raw");
|
||||||
|
|
||||||
|
if (raw.length () > 3 &&
|
||||||
|
raw.substr (0, 3) == "rc.")
|
||||||
|
{
|
||||||
|
auto sep = raw.find ('=', 3);
|
||||||
|
if (sep == std::string::npos)
|
||||||
|
sep = raw.find (':', 3);
|
||||||
|
if (sep != std::string::npos)
|
||||||
|
{
|
||||||
|
a.tag ("CONFIG");
|
||||||
|
a.attribute ("name", raw.substr (3, sep - 3));
|
||||||
|
a.attribute ("value", raw.substr (sep + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Scan all arguments and canonicalize names that need it.
|
// Scan all arguments and canonicalize names that need it.
|
||||||
void CLI::canonicalizeNames ()
|
void CLI::canonicalizeNames ()
|
||||||
|
@ -401,6 +428,7 @@ void CLI::identifyFilter ()
|
||||||
{
|
{
|
||||||
if (a.hasTag ("CMD") ||
|
if (a.hasTag ("CMD") ||
|
||||||
a.hasTag ("EXT") ||
|
a.hasTag ("EXT") ||
|
||||||
|
a.hasTag ("CONFIG") ||
|
||||||
a.hasTag ("BINARY"))
|
a.hasTag ("BINARY"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void handleArg0 ();
|
void handleArg0 ();
|
||||||
void lexArguments ();
|
void lexArguments ();
|
||||||
|
void identifyOverrides ();
|
||||||
void canonicalizeNames ();
|
void canonicalizeNames ();
|
||||||
void identifyFilter ();
|
void identifyFilter ();
|
||||||
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