diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 6486a3cf7..c3157c56c 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -130,10 +130,8 @@ void Cmd::load () if (commands.size () == 0) { commands.push_back ("_projects"); - commands.push_back ("_ids"); commands.push_back ("_config"); commands.push_back ("_query"); - commands.push_back ("_zshids"); commands.push_back ("export.csv"); commands.push_back ("export.ical"); commands.push_back ("export.yaml"); @@ -145,7 +143,6 @@ void Cmd::load () commands.push_back ("burndown.weekly"); commands.push_back ("burndown.monthly"); commands.push_back ("count"); - commands.push_back ("ids"); commands.push_back ("add"); commands.push_back ("append"); commands.push_back ("annotate"); @@ -225,10 +222,8 @@ void Cmd::allCommands (std::vector & all) const bool Cmd::isReadOnlyCommand () { if (command == "_projects" || - command == "_ids" || command == "_config" || command == "_query" || - command == "_zshids" || command == "export.csv" || command == "export.ical" || command == "export.yaml" || @@ -240,7 +235,6 @@ bool Cmd::isReadOnlyCommand () command == "burndown.weekly" || command == "burndown.monthly" || command == "count" || - command == "ids" || command == "calendar" || command == "colors" || command == "config" || diff --git a/src/Context.cpp b/src/Context.cpp index e24ba1363..b48eb9b9a 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -281,12 +281,9 @@ int Context::dispatch (std::string &out) else if (cmd.command == "push") { handlePush (out); } else if (cmd.command == "pull") { handlePull (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 == "_ids") { rc = handleCompletionIDs (out); } else if (cmd.command == "_config") { rc = handleCompletionConfig (out); } else if (cmd.command == "_query") { rc = handleQuery (out); } - else if (cmd.command == "_zshids") { rc = handleZshCompletionIDs (out); } else if (cmd.command == "" && sequence.size ()) { rc = handleModify (out); } diff --git a/src/command.cpp b/src/command.cpp index 2ce060dc9..be538cd0e 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -385,54 +385,6 @@ int handleQuery (std::string& outs) return rc; } -//////////////////////////////////////////////////////////////////////////////// -int handleCompletionIDs (std::string& outs) -{ - std::vector tasks; - context.tdb.lock (context.config.getBoolean ("locking")); - Filter filter; - context.tdb.loadPending (tasks, filter); - context.tdb.commit (); - context.tdb.unlock (); - - std::vector 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 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 () { @@ -1532,30 +1484,6 @@ int handleCount (std::string& outs) return rc; } -//////////////////////////////////////////////////////////////////////////////// -int handleIds (std::string& outs) -{ - int rc = 0; - - // Scan the pending tasks, applying any filter. - std::vector 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 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) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index f9bf3d843..d701199a4 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -12,6 +12,7 @@ set (commands_SRCS Command.cpp Command.h CmdEdit.cpp CmdEdit.h CmdExec.cpp CmdExec.h CmdHelp.cpp CmdHelp.h + CmdIds.cpp CmdIds.h CmdInfo.cpp CmdInfo.h CmdInstall.cpp CmdInstall.h CmdLogo.cpp CmdLogo.h diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 0acd2fa2d..b7b4de6c6 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -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, 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 (); view.set (row, 1, "task config [name [value | '']]"); view.set (row, 2, "Add, modify and remove settings in the task configuration."); diff --git a/src/commands/CmdIDs.cpp b/src/commands/CmdIDs.cpp new file mode 100644 index 000000000..152007f51 --- /dev/null +++ b/src/commands/CmdIDs.cpp @@ -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 +#include +#include +#include +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdIds::CmdIds () +{ + _keyword = "ids"; + _usage = "task ids []"; + _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 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 ids; + std::vector ::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 []"; + _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 tasks; + context.tdb.lock (context.config.getBoolean ("locking")); + Filter filter; + context.tdb.loadPending (tasks, filter); + context.tdb.commit (); + context.tdb.unlock (); + + std::vector ids; + std::vector ::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 ::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 []"; + _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 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 ::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; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdIDs.h b/src/commands/CmdIDs.h new file mode 100644 index 000000000..e7cda3a7c --- /dev/null +++ b/src/commands/CmdIDs.h @@ -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 +#include + +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 +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index dd318992c..13e1c0190 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -54,12 +55,14 @@ void Command::factory (std::map & all) Command* c; c = new CmdCompletionCommands (); all[c->keyword ()] = c; + c = new CmdCompletionIds (); all[c->keyword ()] = c; c = new CmdCompletionTags (); all[c->keyword ()] = c; c = new CmdCompletionVersion (); all[c->keyword ()] = c; c = new CmdDiagnostics (); all[c->keyword ()] = c; c = new CmdEdit (); all[c->keyword ()] = c; c = new CmdExec (); 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 CmdInstall (); all[c->keyword ()] = c; c = new CmdLogo (); all[c->keyword ()] = c; @@ -71,6 +74,7 @@ void Command::factory (std::map & all) c = new CmdUrgency (); all[c->keyword ()] = c; c = new CmdVersion (); 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. std::vector variables; diff --git a/src/main.h b/src/main.h index 5ee8f4c45..38df67702 100644 --- a/src/main.h +++ b/src/main.h @@ -58,10 +58,8 @@ int handleDone (std::string&); int handleModify (std::string&); int handleProjects (std::string&); int handleCompletionProjects (std::string&); -int handleCompletionIDs (std::string&); int handleCompletionConfig (std::string&); int handleQuery (std::string&); -int handleZshCompletionIDs (std::string&); int handleConfig (std::string&); int handleDelete (std::string&); int handleStart (std::string&); @@ -71,7 +69,6 @@ int handleAnnotate (std::string&); int handleDenotate (std::string&); int handleDuplicate (std::string&); int handleCount (std::string&); -int handleIds (std::string&); void handleUndo (); void handleMerge (std::string&); void handlePush (std::string&);