mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-25 21:27:19 +02:00
Commands - _tags
- Migrated handleCompletionTags to CmdTags.
This commit is contained in:
parent
b075f1252c
commit
330b148ca9
7 changed files with 64 additions and 47 deletions
|
@ -130,7 +130,6 @@ void Cmd::load ()
|
||||||
if (commands.size () == 0)
|
if (commands.size () == 0)
|
||||||
{
|
{
|
||||||
commands.push_back ("_projects");
|
commands.push_back ("_projects");
|
||||||
commands.push_back ("_tags");
|
|
||||||
commands.push_back ("_commands");
|
commands.push_back ("_commands");
|
||||||
commands.push_back ("_ids");
|
commands.push_back ("_ids");
|
||||||
commands.push_back ("_config");
|
commands.push_back ("_config");
|
||||||
|
@ -230,7 +229,6 @@ void Cmd::allCommands (std::vector <std::string>& all) const
|
||||||
bool Cmd::isReadOnlyCommand ()
|
bool Cmd::isReadOnlyCommand ()
|
||||||
{
|
{
|
||||||
if (command == "_projects" ||
|
if (command == "_projects" ||
|
||||||
command == "_tags" ||
|
|
||||||
command == "_commands" ||
|
command == "_commands" ||
|
||||||
command == "_ids" ||
|
command == "_ids" ||
|
||||||
command == "_config" ||
|
command == "_config" ||
|
||||||
|
|
|
@ -284,7 +284,6 @@ int Context::dispatch (std::string &out)
|
||||||
else if (cmd.command == "count") { rc = handleCount (out); }
|
else if (cmd.command == "count") { rc = handleCount (out); }
|
||||||
else if (cmd.command == "ids") { rc = handleIds (out); }
|
else if (cmd.command == "ids") { rc = handleIds (out); }
|
||||||
else if (cmd.command == "_projects") { rc = handleCompletionProjects (out); }
|
else if (cmd.command == "_projects") { rc = handleCompletionProjects (out); }
|
||||||
else if (cmd.command == "_tags") { rc = handleCompletionTags (out); }
|
|
||||||
else if (cmd.command == "_commands") { rc = handleCompletionCommands (out); }
|
else if (cmd.command == "_commands") { rc = handleCompletionCommands (out); }
|
||||||
else if (cmd.command == "_ids") { rc = handleCompletionIDs (out); }
|
else if (cmd.command == "_ids") { rc = handleCompletionIDs (out); }
|
||||||
else if (cmd.command == "_config") { rc = handleCompletionConfig (out); }
|
else if (cmd.command == "_config") { rc = handleCompletionConfig (out); }
|
||||||
|
|
|
@ -331,49 +331,6 @@ int handleCompletionProjects (std::string& outs)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
int handleCompletionTags (std::string& outs)
|
|
||||||
{
|
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
|
|
||||||
Filter filter;
|
|
||||||
if (context.config.getBoolean ("complete.all.tags"))
|
|
||||||
context.tdb.load (tasks, filter);
|
|
||||||
else
|
|
||||||
context.tdb.loadPending (tasks, filter);
|
|
||||||
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
// Scan all the tasks for their tags, building a map using tag
|
|
||||||
// names as keys.
|
|
||||||
std::map <std::string, int> unique;
|
|
||||||
foreach (t, tasks)
|
|
||||||
{
|
|
||||||
std::vector <std::string> tags;
|
|
||||||
t->getTags (tags);
|
|
||||||
|
|
||||||
foreach (tag, tags)
|
|
||||||
unique[*tag] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add built-in tags to map
|
|
||||||
unique["nocolor"] = 0;
|
|
||||||
unique["nonag"] = 0;
|
|
||||||
unique["nocal"] = 0;
|
|
||||||
unique["next"] = 0;
|
|
||||||
unique["stall"] = 0;
|
|
||||||
unique["someday"] = 0;
|
|
||||||
|
|
||||||
std::stringstream out;
|
|
||||||
foreach (tag, unique)
|
|
||||||
out << tag->first << "\n";
|
|
||||||
|
|
||||||
outs = out.str ();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int handleCompletionCommands (std::string& outs)
|
int handleCompletionCommands (std::string& outs)
|
||||||
{
|
{
|
||||||
|
|
|
@ -121,3 +121,59 @@ int CmdTags::execute (const std::string& command_line, std::string& output)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CmdCompletionTags::CmdCompletionTags ()
|
||||||
|
{
|
||||||
|
_keyword = "_tags";
|
||||||
|
_usage = "task _tags";
|
||||||
|
_description = "Shows only a list of all tags used.";
|
||||||
|
_read_only = true;
|
||||||
|
_displays_id = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int CmdCompletionTags::execute (const std::string& command_line, std::string& output)
|
||||||
|
{
|
||||||
|
std::vector <Task> tasks;
|
||||||
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
|
|
||||||
|
Filter filter;
|
||||||
|
if (context.config.getBoolean ("complete.all.tags"))
|
||||||
|
context.tdb.load (tasks, filter);
|
||||||
|
else
|
||||||
|
context.tdb.loadPending (tasks, filter);
|
||||||
|
|
||||||
|
context.tdb.commit ();
|
||||||
|
context.tdb.unlock ();
|
||||||
|
|
||||||
|
// Scan all the tasks for their tags, building a map using tag
|
||||||
|
// names as keys.
|
||||||
|
std::map <std::string, int> unique;
|
||||||
|
std::vector <Task>::iterator task;
|
||||||
|
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||||
|
{
|
||||||
|
std::vector <std::string> tags;
|
||||||
|
task->getTags (tags);
|
||||||
|
|
||||||
|
std::vector <std::string>::iterator tag;
|
||||||
|
for (tag = tags.begin (); tag != tags.end (); ++tag)
|
||||||
|
unique[*tag] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add built-in tags to map
|
||||||
|
unique["nocolor"] = 0;
|
||||||
|
unique["nonag"] = 0;
|
||||||
|
unique["nocal"] = 0;
|
||||||
|
unique["next"] = 0;
|
||||||
|
unique["stall"] = 0;
|
||||||
|
unique["someday"] = 0;
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
std::map <std::string, int>::iterator it;
|
||||||
|
for (it = unique.begin (); it != unique.end (); ++it)
|
||||||
|
out << it->first << "\n";
|
||||||
|
|
||||||
|
output = out.str ();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -38,5 +38,12 @@ public:
|
||||||
int execute (const std::string&, std::string&);
|
int execute (const std::string&, std::string&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CmdCompletionTags : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CmdCompletionTags ();
|
||||||
|
int execute (const std::string&, std::string&);
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -51,6 +51,7 @@ void Command::factory (std::map <std::string, Command*>& all)
|
||||||
{
|
{
|
||||||
Command* c;
|
Command* c;
|
||||||
|
|
||||||
|
c = new CmdCompletionTags (); all[c->keyword ()] = c;
|
||||||
c = new CmdCompletionVersion (); all[c->keyword ()] = c;
|
c = new CmdCompletionVersion (); all[c->keyword ()] = c;
|
||||||
c = new CmdDiagnostics (); all[c->keyword ()] = c;
|
c = new CmdDiagnostics (); all[c->keyword ()] = c;
|
||||||
c = new CmdEdit (); all[c->keyword ()] = c;
|
c = new CmdEdit (); all[c->keyword ()] = c;
|
||||||
|
|
|
@ -58,7 +58,6 @@ int handleDone (std::string&);
|
||||||
int handleModify (std::string&);
|
int handleModify (std::string&);
|
||||||
int handleProjects (std::string&);
|
int handleProjects (std::string&);
|
||||||
int handleCompletionProjects (std::string&);
|
int handleCompletionProjects (std::string&);
|
||||||
int handleCompletionTags (std::string&);
|
|
||||||
int handleCompletionCommands (std::string&);
|
int handleCompletionCommands (std::string&);
|
||||||
int handleCompletionIDs (std::string&);
|
int handleCompletionIDs (std::string&);
|
||||||
int handleCompletionConfig (std::string&);
|
int handleCompletionConfig (std::string&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue