mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 04:27:20 +02:00
Helper Command
- Added _query helper command for script writers, which accepts a filter like any other report, but returns raw JSON.
This commit is contained in:
parent
126a3d88b5
commit
7f32435ce9
8 changed files with 72 additions and 0 deletions
|
@ -135,6 +135,7 @@ void Cmd::load ()
|
|||
commands.push_back ("_config");
|
||||
commands.push_back ("_version");
|
||||
commands.push_back ("_urgency");
|
||||
commands.push_back ("_query");
|
||||
commands.push_back ("export.csv");
|
||||
commands.push_back ("export.ical");
|
||||
commands.push_back ("export.yaml");
|
||||
|
@ -241,6 +242,7 @@ bool Cmd::isReadOnlyCommand ()
|
|||
command == "_config" ||
|
||||
command == "_version" ||
|
||||
command == "_urgency" ||
|
||||
command == "_query" ||
|
||||
command == "export.csv" ||
|
||||
command == "export.ical" ||
|
||||
command == "export.yaml" ||
|
||||
|
|
|
@ -259,6 +259,7 @@ int Context::dispatch (std::string &out)
|
|||
else if (cmd.command == "_config") { rc = handleCompletionConfig (out); }
|
||||
else if (cmd.command == "_version") { rc = handleCompletionVersion (out); }
|
||||
else if (cmd.command == "_urgency") { rc = handleUrgency (out); }
|
||||
else if (cmd.command == "_query") { rc = handleQuery (out); }
|
||||
else if (cmd.command == "" &&
|
||||
sequence.size ()) { rc = handleModify (out); }
|
||||
|
||||
|
|
23
src/Task.cpp
23
src/Task.cpp
|
@ -423,6 +423,29 @@ std::string Task::composeYAML () const
|
|||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Task::composeJSON () const
|
||||
{
|
||||
std::stringstream out;
|
||||
out << "{";
|
||||
|
||||
std::map <std::string, Att>::const_iterator i;
|
||||
for (i = this->begin (); i != this->end (); ++i)
|
||||
{
|
||||
if (i != this->begin ())
|
||||
out << ",";
|
||||
|
||||
out << "\""
|
||||
<< i->second.name ()
|
||||
<< "\":\""
|
||||
<< i->second.value ()
|
||||
<< "\"";
|
||||
}
|
||||
|
||||
out << "}";
|
||||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::getAnnotations (std::vector <Att>& annotations) const
|
||||
{
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
void parse (const std::string&);
|
||||
std::string composeCSV () const;
|
||||
std::string composeYAML () const;
|
||||
std::string composeJSON () const;
|
||||
|
||||
// Status values.
|
||||
enum status {pending, completed, deleted, recurring, waiting};
|
||||
|
|
|
@ -552,6 +552,46 @@ int handleUrgency (std::string& outs)
|
|||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleQuery (std::string& outs)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (context.hooks.trigger ("pre-query-command"))
|
||||
{
|
||||
// Get all the tasks.
|
||||
std::vector <Task> tasks;
|
||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||
handleRecurrence ();
|
||||
context.tdb.load (tasks, context.filter);
|
||||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter sequence.
|
||||
if (context.sequence.size ())
|
||||
context.filter.applySequence (tasks, context.sequence);
|
||||
|
||||
// Note: "limit:" feature not supported.
|
||||
|
||||
// Compose output.
|
||||
outs = "{";
|
||||
std::vector <Task>::iterator t;
|
||||
for (t = tasks.begin (); t != tasks.end (); ++t)
|
||||
{
|
||||
if (t != tasks.begin ())
|
||||
outs += ",\n";
|
||||
|
||||
outs += t->composeJSON ();
|
||||
}
|
||||
|
||||
outs += "}\n";
|
||||
|
||||
context.hooks.trigger ("post-query-command");
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleCompletionIDs (std::string& outs)
|
||||
{
|
||||
|
|
|
@ -68,6 +68,7 @@ int handleCompletionIDs (std::string&);
|
|||
int handleCompletionConfig (std::string&);
|
||||
int handleCompletionVersion (std::string&);
|
||||
int handleUrgency (std::string&);
|
||||
int handleQuery (std::string&);
|
||||
int handleVersion (std::string&);
|
||||
int handleConfig (std::string&);
|
||||
int handleShow (std::string&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue