mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - _commands
- Added undocumented _commands command to support completion scripts.
This commit is contained in:
parent
a6e9e6cdfb
commit
f633e42597
5 changed files with 28 additions and 0 deletions
11
src/Cmd.cpp
11
src/Cmd.cpp
|
@ -108,6 +108,7 @@ void Cmd::load ()
|
|||
{
|
||||
commands.push_back ("_projects");
|
||||
commands.push_back ("_tags");
|
||||
commands.push_back ("_commands");
|
||||
commands.push_back (context.stringtable.get (CMD_ADD, "add"));
|
||||
commands.push_back (context.stringtable.get (CMD_APPEND, "append"));
|
||||
commands.push_back (context.stringtable.get (CMD_ANNOTATE, "annotate"));
|
||||
|
@ -180,12 +181,22 @@ void Cmd::allCustomReports (std::vector <std::string>& all) const
|
|||
all = customReports;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Cmd::allCommands (std::vector <std::string>& all) const
|
||||
{
|
||||
all.clear ();
|
||||
foreach (command, commands)
|
||||
if (command->substr (0, 1) != "_")
|
||||
all.push_back (*command);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Commands that do not directly modify the data files.
|
||||
bool Cmd::isReadOnlyCommand ()
|
||||
{
|
||||
if (command == "_projects" ||
|
||||
command == "_tags" ||
|
||||
command == "_commands" ||
|
||||
command == context.stringtable.get (CMD_CALENDAR, "calendar") ||
|
||||
command == context.stringtable.get (CMD_COLORS, "colors") ||
|
||||
command == context.stringtable.get (CMD_EXPORT, "export") ||
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
bool validCustom (const std::string&);
|
||||
void parse (const std::string&);
|
||||
void allCustomReports (std::vector <std::string>&) const;
|
||||
void allCommands (std::vector <std::string>&) const;
|
||||
|
||||
bool isReadOnlyCommand ();
|
||||
bool isWriteCommand ();
|
||||
|
|
|
@ -198,6 +198,7 @@ std::string Context::dispatch ()
|
|||
else if (cmd.command == "undo") { handleUndo (); }
|
||||
else if (cmd.command == "_projects") { out = handleCompletionProjects (); }
|
||||
else if (cmd.command == "_tags") { out = handleCompletionTags (); }
|
||||
else if (cmd.command == "_commands") { out = handleCompletionCommands (); }
|
||||
else if (cmd.command == "" &&
|
||||
sequence.size ()) { out = handleModify (); }
|
||||
|
||||
|
|
|
@ -315,6 +315,20 @@ std::string handleCompletionTags ()
|
|||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string handleCompletionCommands ()
|
||||
{
|
||||
std::vector <std::string> commands;
|
||||
context.cmd.allCommands (commands);
|
||||
std::sort (commands.begin (), commands.end ());
|
||||
|
||||
std::stringstream out;
|
||||
foreach (command, commands)
|
||||
out << *command << std::endl;
|
||||
|
||||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void handleUndo ()
|
||||
{
|
||||
|
|
|
@ -63,6 +63,7 @@ std::string handleProjects ();
|
|||
std::string handleCompletionProjects ();
|
||||
std::string handleTags ();
|
||||
std::string handleCompletionTags ();
|
||||
std::string handleCompletionCommands ();
|
||||
std::string handleVersion ();
|
||||
std::string handleDelete ();
|
||||
std::string handleStart ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue