diff --git a/src/Cmd.cpp b/src/Cmd.cpp index c3157c56c..b34b9fdfe 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -142,7 +142,6 @@ void Cmd::load () commands.push_back ("burndown.daily"); commands.push_back ("burndown.weekly"); commands.push_back ("burndown.monthly"); - commands.push_back ("count"); commands.push_back ("add"); commands.push_back ("append"); commands.push_back ("annotate"); @@ -234,7 +233,6 @@ bool Cmd::isReadOnlyCommand () command == "burndown.daily" || command == "burndown.weekly" || command == "burndown.monthly" || - command == "count" || command == "calendar" || command == "colors" || command == "config" || diff --git a/src/Context.cpp b/src/Context.cpp index b48eb9b9a..f5035cd1e 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -280,7 +280,6 @@ int Context::dispatch (std::string &out) handleMerge (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 == "_projects") { rc = handleCompletionProjects (out); } else if (cmd.command == "_config") { rc = handleCompletionConfig (out); } else if (cmd.command == "_query") { rc = handleQuery (out); } diff --git a/src/command.cpp b/src/command.cpp index be538cd0e..d962309f0 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1457,33 +1457,6 @@ int handleDuplicate (std::string& outs) return rc; } -//////////////////////////////////////////////////////////////////////////////// -int handleCount (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. Skip recurring parent tasks. - int count = 0; - std::vector ::iterator it; - for (it = tasks.begin (); it != tasks.end (); ++it) - if (it->getStatus () != Task::recurring) - ++count; - - std::stringstream out; - out << count << "\n"; - outs = out.str (); - - return rc; -} - //////////////////////////////////////////////////////////////////////////////// int handleColor (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index d701199a4..919a44e9d 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -7,6 +7,7 @@ include_directories (${CMAKE_SOURCE_DIR} set (commands_SRCS Command.cpp Command.h CmdCommands.cpp CmdCommands.h + CmdCount.cpp CmdCount.h CmdCustom.cpp CmdCustom.h CmdDiagnostics.cpp CmdDiagnostics.h CmdEdit.cpp CmdEdit.h diff --git a/src/commands/CmdCount.cpp b/src/commands/CmdCount.cpp new file mode 100644 index 000000000..f4130449a --- /dev/null +++ b/src/commands/CmdCount.cpp @@ -0,0 +1,69 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdCount::CmdCount () +{ + _keyword = "count"; + _usage = "task count []"; + _description = "Shows only the number of matching tasks."; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdCount::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. Skip recurring parent tasks. + int count = 0; + std::vector ::iterator it; + for (it = tasks.begin (); it != tasks.end (); ++it) + if (it->getStatus () != Task::recurring) + ++count; + + std::stringstream out; + out << count << "\n"; + output = out.str (); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdCount.h b/src/commands/CmdCount.h new file mode 100644 index 000000000..ffdef0bf6 --- /dev/null +++ b/src/commands/CmdCount.h @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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_CMDCOUNT +#define INCLUDED_CMDCOUNT +#define L10N // Localization complete. + +#include +#include + +class CmdCount : public Command +{ +public: + CmdCount (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index b7b4de6c6..93d300ca2 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -232,10 +232,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output) view.set (row, 2, "Displays all possible colors, a named sample, or a " "legend containing all currently defined colors."); - row = view.addRow (); - 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 config [name [value | '']]"); view.set (row, 2, "Add, modify and remove settings in the task configuration."); diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 13e1c0190..e0c2dad8a 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,7 @@ void Command::factory (std::map & all) c = new CmdCompletionIds (); all[c->keyword ()] = c; c = new CmdCompletionTags (); all[c->keyword ()] = c; c = new CmdCompletionVersion (); all[c->keyword ()] = c; + c = new CmdCount (); 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; diff --git a/src/main.h b/src/main.h index 38df67702..d3ccd5382 100644 --- a/src/main.h +++ b/src/main.h @@ -68,7 +68,6 @@ int handleColor (std::string&); int handleAnnotate (std::string&); int handleDenotate (std::string&); int handleDuplicate (std::string&); -int handleCount (std::string&); void handleUndo (); void handleMerge (std::string&); void handlePush (std::string&);