mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Command Location
- Locateѕ, cnaonicalized and categorizes first command.
This commit is contained in:
parent
1495710aca
commit
8429df3b5c
4 changed files with 77 additions and 16 deletions
|
@ -80,15 +80,15 @@ The eval needs of this command are:
|
|||
The parse tree should be:
|
||||
|
||||
+- add COMMAND
|
||||
+- "one" WORD
|
||||
+- attr
|
||||
| +- due ATTRIBUTE
|
||||
| +- expr
|
||||
| | + "eoy" LITERAL DATE
|
||||
+- attr
|
||||
+- wait ATTRIBUTE
|
||||
+- expr
|
||||
+= "due" DOM DATE
|
||||
+= "-" OP
|
||||
+= "2wks" LITERAL DURATION
|
||||
+- "one" WORD
|
||||
+- attr
|
||||
| +- due ATTRIBUTE
|
||||
| +- expr
|
||||
| | + "eoy" LITERAL DATE
|
||||
+- attr
|
||||
+- wait ATTRIBUTE
|
||||
+- expr
|
||||
+= "due" DOM DATE
|
||||
+= "-" OP
|
||||
+= "2wks" LITERAL DURATION
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ A3t::A3t (int argc, char** argv)
|
|||
{
|
||||
Tree* branch = _tree->addBranch (new Tree (format ("arg{1}", i)));
|
||||
branch->attribute ("raw", argv[i]);
|
||||
branch->tag ("original");
|
||||
branch->tag ("ORIGINAL");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,8 @@ A3t::~A3t ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
Tree* A3t::parse ()
|
||||
{
|
||||
findCommand ();
|
||||
|
||||
return _tree;
|
||||
}
|
||||
|
||||
|
@ -83,7 +85,55 @@ bool A3t::canonicalize (
|
|||
|
||||
// Match against the options, throw away results.
|
||||
std::vector <std::string> matches;
|
||||
return autoComplete (canonicalized, options, matches, minimumMatchLength) == 1 ? true : false;
|
||||
if (autoComplete (value, options, matches, minimumMatchLength) == 1)
|
||||
{
|
||||
// for (auto& i: matches)
|
||||
// std::cout << "match: " << i << "\n";
|
||||
|
||||
canonicalized = matches[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Walk the top-level tree branches, looking for the first raw value that
|
||||
// autoCompletes to a valid command/report.
|
||||
void A3t::findCommand ()
|
||||
{
|
||||
std::string command;
|
||||
for (int i = 0; i < _tree->branches (); ++i)
|
||||
{
|
||||
if (canonicalize (command, "report", (*_tree)[i]->attribute ("raw")))
|
||||
{
|
||||
(*_tree)[i]->attribute ("canonical", command);
|
||||
(*_tree)[i]->tag ("REPORT");
|
||||
(*_tree)[i]->tag ("CMD");
|
||||
}
|
||||
|
||||
else if (canonicalize (command, "readcmd", (*_tree)[i]->attribute ("raw")))
|
||||
{
|
||||
(*_tree)[i]->attribute ("canonical", command);
|
||||
(*_tree)[i]->tag ("READCMD");
|
||||
(*_tree)[i]->tag ("CMD");
|
||||
}
|
||||
|
||||
else if (canonicalize (command, "writecmd", (*_tree)[i]->attribute ("raw")))
|
||||
{
|
||||
(*_tree)[i]->attribute ("canonical", command);
|
||||
(*_tree)[i]->tag ("WRITECMD");
|
||||
(*_tree)[i]->tag ("CMD");
|
||||
}
|
||||
|
||||
else if (canonicalize (command, "specialcmd", (*_tree)[i]->attribute ("raw")))
|
||||
{
|
||||
(*_tree)[i]->attribute ("canonical", command);
|
||||
(*_tree)[i]->tag ("SPECIALCMD");
|
||||
(*_tree)[i]->tag ("CMD");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -40,6 +40,9 @@ public:
|
|||
void identity (const std::string&, const std::string&);
|
||||
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
||||
|
||||
private:
|
||||
void findCommand ();
|
||||
|
||||
private:
|
||||
Tree* _tree;
|
||||
std::multimap <std::string, std::string> _entities;
|
||||
|
|
|
@ -41,9 +41,17 @@ int main (int argc, char** argv)
|
|||
A3t a3t (argc, argv);
|
||||
|
||||
// Populate identity lists.
|
||||
a3t.identity ("report", "list");
|
||||
a3t.identity ("readcmd", "info");
|
||||
a3t.identity ("writecmd", "modify");
|
||||
a3t.identity ("report", "list");
|
||||
a3t.identity ("report", "next");
|
||||
|
||||
a3t.identity ("readcmd", "info");
|
||||
a3t.identity ("readcmd", "projects");
|
||||
|
||||
a3t.identity ("writecmd", "add");
|
||||
a3t.identity ("writecmd", "modify");
|
||||
|
||||
a3t.identity ("specialcmd", "calendar");
|
||||
a3t.identity ("specialcmd", "edit");
|
||||
|
||||
Tree* tree = a3t.parse ();
|
||||
if (tree)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue