From 908fbd8ca456aef42acf2f2722c328388e34d728 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 30 May 2011 13:53:57 -0400 Subject: [PATCH] Commands - done - Migrated handleDone to CmdDone. --- src/Cmd.cpp | 2 - src/Context.cpp | 3 +- src/command.cpp | 108 ------------------------- src/commands/CMakeLists.txt | 1 + src/commands/CmdDone.cpp | 155 ++++++++++++++++++++++++++++++++++++ src/commands/CmdDone.h | 42 ++++++++++ src/commands/CmdHelp.cpp | 4 - src/commands/Command.cpp | 2 + src/main.h | 1 - 9 files changed, 201 insertions(+), 117 deletions(-) create mode 100644 src/commands/CmdDone.cpp create mode 100644 src/commands/CmdDone.h diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 51b3cac28..ed42a003c 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -130,7 +130,6 @@ void Cmd::load () if (commands.size () == 0) { commands.push_back ("delete"); - commands.push_back ("done"); commands.push_back ("merge"); commands.push_back ("push"); commands.push_back ("pull"); @@ -203,7 +202,6 @@ bool Cmd::isWriteCommand () { if (command == "merge" || command == "delete" || - command == "done" || command == "pull") return true; diff --git a/src/Context.cpp b/src/Context.cpp index ffe16f13a..fbdc77791 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -249,8 +249,7 @@ int Context::dispatch (std::string &out) Timer t ("Context::dispatch"); // TODO Chain-of-command pattern dispatch. - if (cmd.command == "done") { rc = handleDone (out); } - else if (cmd.command == "delete") { rc = handleDelete (out); } + if (cmd.command == "delete") { rc = handleDelete (out); } else if (cmd.command == "merge") { tdb.gc (); handleMerge (out); } else if (cmd.command == "push") { handlePush (out); } diff --git a/src/command.cpp b/src/command.cpp index 1dddcd9a6..f6427592d 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -367,114 +367,6 @@ int handleDelete (std::string& outs) return rc; } -//////////////////////////////////////////////////////////////////////////////// -int handleDone (std::string& outs) -{ - int rc = 0; - int count = 0; - std::stringstream out; - - std::vector tasks; - context.tdb.lock (context.config.getBoolean ("locking")); - Filter filter; - context.tdb.loadPending (tasks, filter); - - // Filter sequence. - std::vector all = tasks; - context.filter.applySequence (tasks, context.sequence); - if (tasks.size () == 0) - { - std::cout << "No tasks specified.\n"; - return 1; - } - - Permission permission; - if (context.sequence.size () > (size_t) context.config.getInteger ("bulk")) - permission.bigSequence (); - - bool nagged = false; - foreach (task, tasks) - { - if (task->getStatus () == Task::pending || - task->getStatus () == Task::waiting) - { - Task before (*task); - - // Apply other deltas. - if (deltaDescription (*task)) - permission.bigChange (); - - deltaTags (*task); - deltaAttributes (*task); - deltaSubstitutions (*task); - - // Add an end date. - char entryTime[16]; - sprintf (entryTime, "%u", (unsigned int) time (NULL)); - task->set ("end", entryTime); - - // Change status. - task->setStatus (Task::completed); - - // Stop the task, if started. - if (task->has ("start") && - context.config.getBoolean ("journal.time")) - task->addAnnotation (context.config.get ("journal.time.stop.annotation")); - - // Only allow valid tasks. - task->validate (); - - if (taskDiff (before, *task)) - { - if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?")) - { - context.tdb.update (*task); - - if (context.config.getBoolean ("echo.command")) - out << "Completed " - << task->id - << " '" - << task->get ("description") - << "'.\n"; - - dependencyChainOnComplete (*task); - context.footnote (onProjectChange (*task, false)); - - ++count; - } - } - - updateRecurrenceMask (all, *task); - if (!nagged) - nagged = nag (*task); - } - else - { - out << "Task " - << task->id - << " '" - << task->get ("description") - << "' is neither pending nor waiting.\n"; - rc = 1; - } - } - - if (count) - context.tdb.commit (); - - context.tdb.unlock (); - - if (context.config.getBoolean ("echo.command")) - out << "Marked " - << count - << " task" - << (count == 1 ? "" : "s") - << " as done.\n"; - - outs = out.str (); - return rc; -} - //////////////////////////////////////////////////////////////////////////////// int handleModify (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index c36781e6e..451df72e4 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -18,6 +18,7 @@ set (commands_SRCS Command.cpp Command.h CmdCustom.cpp CmdCustom.h CmdDenotate.cpp CmdDenotate.h CmdDiagnostics.cpp CmdDiagnostics.h + CmdDone.cpp CmdDone.h CmdDuplicate.cpp CmdDuplicate.h CmdEdit.cpp CmdEdit.h CmdExec.cpp CmdExec.h diff --git a/src/commands/CmdDone.cpp b/src/commands/CmdDone.cpp new file mode 100644 index 000000000..df4ce9221 --- /dev/null +++ b/src/commands/CmdDone.cpp @@ -0,0 +1,155 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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; + +//////////////////////////////////////////////////////////////////////////////// +CmdDone::CmdDone () +{ + _keyword = "done"; + _usage = "task done ID [tags] [attrs] [desc...]"; + _description = "Marks the specified task as completed."; + _read_only = false; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdDone::execute (const std::string&, std::string& output) +{ + int rc = 0; + int count = 0; + std::stringstream out; + + std::vector tasks; + context.tdb.lock (context.config.getBoolean ("locking")); + Filter filter; + context.tdb.loadPending (tasks, filter); + + // Filter sequence. + std::vector all = tasks; + context.filter.applySequence (tasks, context.sequence); + if (tasks.size () == 0) + { + context.footnote ("No tasks specified."); + return 1; + } + + Permission permission; + if (context.sequence.size () > (size_t) context.config.getInteger ("bulk")) + permission.bigSequence (); + + bool nagged = false; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + { + if (task->getStatus () == Task::pending || + task->getStatus () == Task::waiting) + { + Task before (*task); + + // Apply other deltas. + if (deltaDescription (*task)) + permission.bigChange (); + + deltaTags (*task); + deltaAttributes (*task); + deltaSubstitutions (*task); + + // Add an end date. + char entryTime[16]; + sprintf (entryTime, "%u", (unsigned int) time (NULL)); + task->set ("end", entryTime); + + // Change status. + task->setStatus (Task::completed); + + // Stop the task, if started. + if (task->has ("start") && + context.config.getBoolean ("journal.time")) + task->addAnnotation (context.config.get ("journal.time.stop.annotation")); + + // Only allow valid tasks. + task->validate (); + + if (taskDiff (before, *task)) + { + if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?")) + { + context.tdb.update (*task); + + if (context.config.getBoolean ("echo.command")) + out << "Completed " + << task->id + << " '" + << task->get ("description") + << "'.\n"; + + dependencyChainOnComplete (*task); + context.footnote (onProjectChange (*task, false)); + + ++count; + } + } + + updateRecurrenceMask (all, *task); + if (!nagged) + nagged = nag (*task); + } + else + { + out << "Task " + << task->id + << " '" + << task->get ("description") + << "' is neither pending nor waiting.\n"; + rc = 1; + } + } + + if (count) + context.tdb.commit (); + + context.tdb.unlock (); + + if (context.config.getBoolean ("echo.command")) + out << "Marked " + << count + << " task" + << (count == 1 ? "" : "s") + << " as done.\n"; + + output = out.str (); + return rc; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdDone.h b/src/commands/CmdDone.h new file mode 100644 index 000000000..7818bac1c --- /dev/null +++ b/src/commands/CmdDone.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_CMDDONE +#define INCLUDED_CMDDONE +#define L10N // Localization complete. + +#include +#include + +class CmdDone : public Command +{ +public: + CmdDone (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 8e3b451fd..ddd0155bd 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -107,10 +107,6 @@ int CmdHelp::execute (const std::string&, std::string& output) view.set (row, 1, "task delete ID"); view.set (row, 2, "Deletes the specified task."); - row = view.addRow (); - view.set (row, 1, "task done ID [tags] [attrs] [desc...]"); - view.set (row, 2, "Marks the specified task as completed."); - row = view.addRow (); view.set (row, 1, "task merge URL"); view.set (row, 2, "Merges the specified undo.data file with the local data files."); diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index aee58731c..14f7f8d30 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -94,6 +95,7 @@ void Command::factory (std::map & all) c = new CmdCount (); all[c->keyword ()] = c; c = new CmdDenotate (); all[c->keyword ()] = c; c = new CmdDiagnostics (); all[c->keyword ()] = c; + c = new CmdDone (); all[c->keyword ()] = c; c = new CmdDuplicate (); 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 0c6bef7fc..cb97c2219 100644 --- a/src/main.h +++ b/src/main.h @@ -50,7 +50,6 @@ int getDueState (const std::string&); bool nag (Task&); // command.cpp -int handleDone (std::string&); int handleModify (std::string&); int handleDelete (std::string&); void handleMerge (std::string&);