Commands - ids, _ids, _zshids
- Migrated handleIds, handleCompletionIds, handleZshCompletionIds to CmdIDs.
This commit is contained in:
@@ -130,10 +130,8 @@ void Cmd::load ()
|
|||||||
if (commands.size () == 0)
|
if (commands.size () == 0)
|
||||||
{
|
{
|
||||||
commands.push_back ("_projects");
|
commands.push_back ("_projects");
|
||||||
commands.push_back ("_ids");
|
|
||||||
commands.push_back ("_config");
|
commands.push_back ("_config");
|
||||||
commands.push_back ("_query");
|
commands.push_back ("_query");
|
||||||
commands.push_back ("_zshids");
|
|
||||||
commands.push_back ("export.csv");
|
commands.push_back ("export.csv");
|
||||||
commands.push_back ("export.ical");
|
commands.push_back ("export.ical");
|
||||||
commands.push_back ("export.yaml");
|
commands.push_back ("export.yaml");
|
||||||
@@ -145,7 +143,6 @@ void Cmd::load ()
|
|||||||
commands.push_back ("burndown.weekly");
|
commands.push_back ("burndown.weekly");
|
||||||
commands.push_back ("burndown.monthly");
|
commands.push_back ("burndown.monthly");
|
||||||
commands.push_back ("count");
|
commands.push_back ("count");
|
||||||
commands.push_back ("ids");
|
|
||||||
commands.push_back ("add");
|
commands.push_back ("add");
|
||||||
commands.push_back ("append");
|
commands.push_back ("append");
|
||||||
commands.push_back ("annotate");
|
commands.push_back ("annotate");
|
||||||
@@ -225,10 +222,8 @@ void Cmd::allCommands (std::vector <std::string>& all) const
|
|||||||
bool Cmd::isReadOnlyCommand ()
|
bool Cmd::isReadOnlyCommand ()
|
||||||
{
|
{
|
||||||
if (command == "_projects" ||
|
if (command == "_projects" ||
|
||||||
command == "_ids" ||
|
|
||||||
command == "_config" ||
|
command == "_config" ||
|
||||||
command == "_query" ||
|
command == "_query" ||
|
||||||
command == "_zshids" ||
|
|
||||||
command == "export.csv" ||
|
command == "export.csv" ||
|
||||||
command == "export.ical" ||
|
command == "export.ical" ||
|
||||||
command == "export.yaml" ||
|
command == "export.yaml" ||
|
||||||
@@ -240,7 +235,6 @@ bool Cmd::isReadOnlyCommand ()
|
|||||||
command == "burndown.weekly" ||
|
command == "burndown.weekly" ||
|
||||||
command == "burndown.monthly" ||
|
command == "burndown.monthly" ||
|
||||||
command == "count" ||
|
command == "count" ||
|
||||||
command == "ids" ||
|
|
||||||
command == "calendar" ||
|
command == "calendar" ||
|
||||||
command == "colors" ||
|
command == "colors" ||
|
||||||
command == "config" ||
|
command == "config" ||
|
||||||
|
|||||||
@@ -281,12 +281,9 @@ int Context::dispatch (std::string &out)
|
|||||||
else if (cmd.command == "push") { handlePush (out); }
|
else if (cmd.command == "push") { handlePush (out); }
|
||||||
else if (cmd.command == "pull") { handlePull (out); }
|
else if (cmd.command == "pull") { handlePull (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 == "_projects") { rc = handleCompletionProjects (out); }
|
else if (cmd.command == "_projects") { rc = handleCompletionProjects (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); }
|
||||||
else if (cmd.command == "_query") { rc = handleQuery (out); }
|
else if (cmd.command == "_query") { rc = handleQuery (out); }
|
||||||
else if (cmd.command == "_zshids") { rc = handleZshCompletionIDs (out); }
|
|
||||||
else if (cmd.command == "" &&
|
else if (cmd.command == "" &&
|
||||||
sequence.size ()) { rc = handleModify (out); }
|
sequence.size ()) { rc = handleModify (out); }
|
||||||
|
|
||||||
|
|||||||
@@ -385,54 +385,6 @@ int handleQuery (std::string& outs)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
int handleCompletionIDs (std::string& outs)
|
|
||||||
{
|
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
Filter filter;
|
|
||||||
context.tdb.loadPending (tasks, filter);
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
std::vector <int> ids;
|
|
||||||
foreach (task, tasks)
|
|
||||||
if (task->getStatus () != Task::deleted &&
|
|
||||||
task->getStatus () != Task::completed)
|
|
||||||
ids.push_back (task->id);
|
|
||||||
|
|
||||||
std::sort (ids.begin (), ids.end ());
|
|
||||||
|
|
||||||
std::stringstream out;
|
|
||||||
foreach (id, ids)
|
|
||||||
out << *id << "\n";
|
|
||||||
|
|
||||||
outs = out.str ();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
int handleZshCompletionIDs (std::string& outs)
|
|
||||||
{
|
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
Filter filter;
|
|
||||||
context.tdb.loadPending (tasks, filter);
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
std::stringstream out;
|
|
||||||
foreach (task, tasks) {
|
|
||||||
if (task->getStatus () != Task::deleted &&
|
|
||||||
task->getStatus () != Task::completed) {
|
|
||||||
out << task->id << ":" << task->get("description") << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
outs = out.str ();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void handleUndo ()
|
void handleUndo ()
|
||||||
{
|
{
|
||||||
@@ -1532,30 +1484,6 @@ int handleCount (std::string& outs)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
int handleIds (std::string& outs)
|
|
||||||
{
|
|
||||||
int rc = 0;
|
|
||||||
|
|
||||||
// Scan the pending tasks, applying any filter.
|
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
handleRecurrence ();
|
|
||||||
context.tdb.load (tasks, context.filter);
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
// Find number of matching tasks.
|
|
||||||
std::vector <int> ids;
|
|
||||||
foreach (task, tasks)
|
|
||||||
if (task->id)
|
|
||||||
ids.push_back (task->id);
|
|
||||||
|
|
||||||
std::sort (ids.begin (), ids.end ());
|
|
||||||
outs = compressIds (ids) + "\n";
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int handleColor (std::string& outs)
|
int handleColor (std::string& outs)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ set (commands_SRCS Command.cpp Command.h
|
|||||||
CmdEdit.cpp CmdEdit.h
|
CmdEdit.cpp CmdEdit.h
|
||||||
CmdExec.cpp CmdExec.h
|
CmdExec.cpp CmdExec.h
|
||||||
CmdHelp.cpp CmdHelp.h
|
CmdHelp.cpp CmdHelp.h
|
||||||
|
CmdIds.cpp CmdIds.h
|
||||||
CmdInfo.cpp CmdInfo.h
|
CmdInfo.cpp CmdInfo.h
|
||||||
CmdInstall.cpp CmdInstall.h
|
CmdInstall.cpp CmdInstall.h
|
||||||
CmdLogo.cpp CmdLogo.h
|
CmdLogo.cpp CmdLogo.h
|
||||||
|
|||||||
@@ -236,10 +236,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output)
|
|||||||
view.set (row, 1, "task count [filter]");
|
view.set (row, 1, "task count [filter]");
|
||||||
view.set (row, 2, "Shows only the number of matching tasks.");
|
view.set (row, 2, "Shows only the number of matching tasks.");
|
||||||
|
|
||||||
row = view.addRow ();
|
|
||||||
view.set (row, 1, "task ids [filter]");
|
|
||||||
view.set (row, 2, "Shows only the IDs of matching tasks, in the form of a range.");
|
|
||||||
|
|
||||||
row = view.addRow ();
|
row = view.addRow ();
|
||||||
view.set (row, 1, "task config [name [value | '']]");
|
view.set (row, 1, "task config [name [value | '']]");
|
||||||
view.set (row, 2, "Add, modify and remove settings in the task configuration.");
|
view.set (row, 2, "Add, modify and remove settings in the task configuration.");
|
||||||
|
|||||||
141
src/commands/CmdIDs.cpp
Normal file
141
src/commands/CmdIDs.cpp
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// taskwarrior - a command line task list manager.
|
||||||
|
//
|
||||||
|
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
|
// Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
// version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
// details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along with
|
||||||
|
// this program; if not, write to the
|
||||||
|
//
|
||||||
|
// Free Software Foundation, Inc.,
|
||||||
|
// 51 Franklin Street, Fifth Floor,
|
||||||
|
// Boston, MA
|
||||||
|
// 02110-1301
|
||||||
|
// USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <Context.h>
|
||||||
|
#include <main.h>
|
||||||
|
#include <util.h>
|
||||||
|
#include <CmdIds.h>
|
||||||
|
|
||||||
|
extern Context context;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CmdIds::CmdIds ()
|
||||||
|
{
|
||||||
|
_keyword = "ids";
|
||||||
|
_usage = "task ids [<filter>]";
|
||||||
|
_description = "Shows only the IDs of matching tasks, in the form of a range.";
|
||||||
|
_read_only = true;
|
||||||
|
_displays_id = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int CmdIds::execute (const std::string& command_line, std::string& output)
|
||||||
|
{
|
||||||
|
// Scan the pending tasks, applying any filter.
|
||||||
|
std::vector <Task> tasks;
|
||||||
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
|
handleRecurrence ();
|
||||||
|
context.tdb.load (tasks, context.filter);
|
||||||
|
context.tdb.commit ();
|
||||||
|
context.tdb.unlock ();
|
||||||
|
|
||||||
|
// Find number of matching tasks.
|
||||||
|
std::vector <int> ids;
|
||||||
|
std::vector <Task>::iterator task;
|
||||||
|
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||||
|
if (task->id)
|
||||||
|
ids.push_back (task->id);
|
||||||
|
|
||||||
|
std::sort (ids.begin (), ids.end ());
|
||||||
|
output = compressIds (ids) + "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CmdCompletionIds::CmdCompletionIds ()
|
||||||
|
{
|
||||||
|
_keyword = "_ids";
|
||||||
|
_usage = "task _ids [<filter>]";
|
||||||
|
_description = "Shows only the IDs of matching tasks, in the form of a list.";
|
||||||
|
_read_only = true;
|
||||||
|
_displays_id = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int CmdCompletionIds::execute (const std::string& command_line, std::string& output)
|
||||||
|
{
|
||||||
|
std::vector <Task> tasks;
|
||||||
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
|
Filter filter;
|
||||||
|
context.tdb.loadPending (tasks, filter);
|
||||||
|
context.tdb.commit ();
|
||||||
|
context.tdb.unlock ();
|
||||||
|
|
||||||
|
std::vector <int> ids;
|
||||||
|
std::vector <Task>::iterator task;
|
||||||
|
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||||
|
if (task->getStatus () != Task::deleted &&
|
||||||
|
task->getStatus () != Task::completed)
|
||||||
|
ids.push_back (task->id);
|
||||||
|
|
||||||
|
std::sort (ids.begin (), ids.end ());
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
std::vector <int>::iterator id;
|
||||||
|
for (id = ids.begin (); id != ids.end (); ++id)
|
||||||
|
out << *id << "\n";
|
||||||
|
|
||||||
|
output = out.str ();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CmdZshCompletionIds::CmdZshCompletionIds ()
|
||||||
|
{
|
||||||
|
_keyword = "_zshids";
|
||||||
|
_usage = "task _zshids [<filter>]";
|
||||||
|
_description = "Shows the IDs and descriptions of matching tasks.";
|
||||||
|
_read_only = true;
|
||||||
|
_displays_id = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int CmdZshCompletionIds::execute (const std::string& command_line, std::string& output)
|
||||||
|
{
|
||||||
|
std::vector <Task> tasks;
|
||||||
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
|
Filter filter;
|
||||||
|
context.tdb.loadPending (tasks, filter);
|
||||||
|
context.tdb.commit ();
|
||||||
|
context.tdb.unlock ();
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
std::vector <Task>::iterator task;
|
||||||
|
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||||
|
if (task->getStatus () != Task::deleted &&
|
||||||
|
task->getStatus () != Task::completed)
|
||||||
|
out << task->id
|
||||||
|
<< ":"
|
||||||
|
<< task->get ("description")
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
output = out.str ();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
56
src/commands/CmdIDs.h
Normal file
56
src/commands/CmdIDs.h
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// taskwarrior - a command line task list manager.
|
||||||
|
//
|
||||||
|
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
|
// Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
// version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
// details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along with
|
||||||
|
// this program; if not, write to the
|
||||||
|
//
|
||||||
|
// Free Software Foundation, Inc.,
|
||||||
|
// 51 Franklin Street, Fifth Floor,
|
||||||
|
// Boston, MA
|
||||||
|
// 02110-1301
|
||||||
|
// USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef INCLUDED_CMDIDS
|
||||||
|
#define INCLUDED_CMDIDS
|
||||||
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <Command.h>
|
||||||
|
|
||||||
|
class CmdIds : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CmdIds ();
|
||||||
|
int execute (const std::string&, std::string&);
|
||||||
|
};
|
||||||
|
|
||||||
|
class CmdCompletionIds : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CmdCompletionIds ();
|
||||||
|
int execute (const std::string&, std::string&);
|
||||||
|
};
|
||||||
|
|
||||||
|
class CmdZshCompletionIds : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CmdZshCompletionIds ();
|
||||||
|
int execute (const std::string&, std::string&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <CmdEdit.h>
|
#include <CmdEdit.h>
|
||||||
#include <CmdExec.h>
|
#include <CmdExec.h>
|
||||||
#include <CmdHelp.h>
|
#include <CmdHelp.h>
|
||||||
|
#include <CmdIds.h>
|
||||||
#include <CmdInfo.h>
|
#include <CmdInfo.h>
|
||||||
#include <CmdInstall.h>
|
#include <CmdInstall.h>
|
||||||
#include <CmdLogo.h>
|
#include <CmdLogo.h>
|
||||||
@@ -54,12 +55,14 @@ void Command::factory (std::map <std::string, Command*>& all)
|
|||||||
Command* c;
|
Command* c;
|
||||||
|
|
||||||
c = new CmdCompletionCommands (); all[c->keyword ()] = c;
|
c = new CmdCompletionCommands (); all[c->keyword ()] = c;
|
||||||
|
c = new CmdCompletionIds (); all[c->keyword ()] = c;
|
||||||
c = new CmdCompletionTags (); all[c->keyword ()] = 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;
|
||||||
c = new CmdExec (); all[c->keyword ()] = c;
|
c = new CmdExec (); all[c->keyword ()] = c;
|
||||||
c = new CmdHelp (); all[c->keyword ()] = c;
|
c = new CmdHelp (); all[c->keyword ()] = c;
|
||||||
|
c = new CmdIds (); all[c->keyword ()] = c;
|
||||||
c = new CmdInfo (); all[c->keyword ()] = c;
|
c = new CmdInfo (); all[c->keyword ()] = c;
|
||||||
c = new CmdInstall (); all[c->keyword ()] = c;
|
c = new CmdInstall (); all[c->keyword ()] = c;
|
||||||
c = new CmdLogo (); all[c->keyword ()] = c;
|
c = new CmdLogo (); all[c->keyword ()] = c;
|
||||||
@@ -71,6 +74,7 @@ void Command::factory (std::map <std::string, Command*>& all)
|
|||||||
c = new CmdUrgency (); all[c->keyword ()] = c;
|
c = new CmdUrgency (); all[c->keyword ()] = c;
|
||||||
c = new CmdVersion (); all[c->keyword ()] = c;
|
c = new CmdVersion (); all[c->keyword ()] = c;
|
||||||
c = new CmdZshCommands (); all[c->keyword ()] = c;
|
c = new CmdZshCommands (); all[c->keyword ()] = c;
|
||||||
|
c = new CmdZshCompletionIds (); all[c->keyword ()] = c;
|
||||||
|
|
||||||
// Instantiate a command object for each custom report.
|
// Instantiate a command object for each custom report.
|
||||||
std::vector <std::string> variables;
|
std::vector <std::string> variables;
|
||||||
|
|||||||
@@ -58,10 +58,8 @@ 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 handleCompletionIDs (std::string&);
|
|
||||||
int handleCompletionConfig (std::string&);
|
int handleCompletionConfig (std::string&);
|
||||||
int handleQuery (std::string&);
|
int handleQuery (std::string&);
|
||||||
int handleZshCompletionIDs (std::string&);
|
|
||||||
int handleConfig (std::string&);
|
int handleConfig (std::string&);
|
||||||
int handleDelete (std::string&);
|
int handleDelete (std::string&);
|
||||||
int handleStart (std::string&);
|
int handleStart (std::string&);
|
||||||
@@ -71,7 +69,6 @@ int handleAnnotate (std::string&);
|
|||||||
int handleDenotate (std::string&);
|
int handleDenotate (std::string&);
|
||||||
int handleDuplicate (std::string&);
|
int handleDuplicate (std::string&);
|
||||||
int handleCount (std::string&);
|
int handleCount (std::string&);
|
||||||
int handleIds (std::string&);
|
|
||||||
void handleUndo ();
|
void handleUndo ();
|
||||||
void handleMerge (std::string&);
|
void handleMerge (std::string&);
|
||||||
void handlePush (std::string&);
|
void handlePush (std::string&);
|
||||||
|
|||||||
Reference in New Issue
Block a user