diff --git a/src/Cmd.cpp b/src/Cmd.cpp index b09639610..600df3c9a 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -142,7 +142,6 @@ void Cmd::load () commands.push_back ("burndown.weekly"); commands.push_back ("burndown.monthly"); commands.push_back ("add"); - commands.push_back ("append"); commands.push_back ("annotate"); commands.push_back ("denotate"); commands.push_back ("calendar"); @@ -247,7 +246,6 @@ bool Cmd::isWriteCommand () { if (command == "merge" || command == "add" || - command == "append" || command == "annotate" || command == "denotate" || command == "delete" || diff --git a/src/Context.cpp b/src/Context.cpp index 1b590cd34..a4f441825 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -261,7 +261,6 @@ int Context::dispatch (std::string &out) else if (cmd.command == "timesheet") { rc = handleReportTimesheet (out); } else if (cmd.command == "add") { rc = handleAdd (out); } else if (cmd.command == "log") { rc = handleLog (out); } - else if (cmd.command == "append") { rc = handleAppend (out); } else if (cmd.command == "annotate") { rc = handleAnnotate (out); } else if (cmd.command == "denotate") { rc = handleDenotate (out); } else if (cmd.command == "done") { rc = handleDone (out); } diff --git a/src/command.cpp b/src/command.cpp index 333e18266..c2dc06a76 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1080,90 +1080,6 @@ int handleModify (std::string& outs) return 0; } -//////////////////////////////////////////////////////////////////////////////// -int handleAppend (std::string& outs) -{ - if (!context.task.has ("description")) - throw std::string ("Additional text must be provided."); - - 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 (); - - foreach (task, tasks) - { - foreach (other, all) - { - if (other->id == task->id || // Self - (task->has ("parent") && - task->get ("parent") == other->get ("parent")) || // Sibling - other->get ("uuid") == task->get ("parent")) // Parent - { - Task before (*other); - - // A non-zero value forces a file write. - int changes = 0; - - // Apply other deltas. - changes += deltaAppend (*other); - changes += deltaTags (*other); - changes += deltaAttributes (*other); - changes += deltaSubstitutions (*other); - - if (taskDiff (before, *other)) - { - // Only allow valid tasks. - other->validate (); - - if (changes && permission.confirmed (before, taskDifferences (before, *other) + "Proceed with change?")) - { - context.tdb.update (*other); - - if (context.config.getBoolean ("echo.command")) - out << "Appended '" - << context.task.get ("description") - << "' to task " - << other->id - << ".\n"; - - if (before.get ("project") != other->get ("project")) - context.footnote (onProjectChange (before, *other)); - - ++count; - } - } - } - } - } - - context.tdb.commit (); - context.tdb.unlock (); - - if (context.config.getBoolean ("echo.command")) - out << "Appended " << count << " task" << (count == 1 ? ".\n" : "s.\n"); - - outs = out.str (); - return rc; -} - //////////////////////////////////////////////////////////////////////////////// int handleDuplicate (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 544edb90a..303254de2 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories (${CMAKE_SOURCE_DIR} ${TASK_INCLUDE_DIRS}) set (commands_SRCS Command.cpp Command.h + CmdAppend.cpp CmdAppend.h CmdCommands.cpp CmdCommands.h CmdCount.cpp CmdCount.h CmdCustom.cpp CmdCustom.h diff --git a/src/commands/CmdAppend.cpp b/src/commands/CmdAppend.cpp new file mode 100644 index 000000000..96d95f3b0 --- /dev/null +++ b/src/commands/CmdAppend.cpp @@ -0,0 +1,132 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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; + +//////////////////////////////////////////////////////////////////////////////// +CmdAppend::CmdAppend () +{ + _keyword = "append"; + _usage = "task append [tags] [attrs] desc..."; + _description = "Append more description to an existing task."; + _read_only = false; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdAppend::execute (const std::string& command_line, std::string& output) +{ + if (!context.task.has ("description")) + throw std::string ("Additional text must be provided."); + + 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 (); + + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + { + std::vector ::iterator other; + for (other = all.begin (); other != all.end (); ++other) + { + if (other->id == task->id || // Self + (task->has ("parent") && + task->get ("parent") == other->get ("parent")) || // Sibling + other->get ("uuid") == task->get ("parent")) // Parent + { + Task before (*other); + + // A non-zero value forces a file write. + int changes = 0; + + // Apply other deltas. + changes += deltaAppend (*other); + changes += deltaTags (*other); + changes += deltaAttributes (*other); + changes += deltaSubstitutions (*other); + + if (taskDiff (before, *other)) + { + // Only allow valid tasks. + other->validate (); + + if (changes && permission.confirmed (before, taskDifferences (before, *other) + "Proceed with change?")) + { + context.tdb.update (*other); + + if (context.config.getBoolean ("echo.command")) + out << "Appended '" + << context.task.get ("description") + << "' to task " + << other->id + << ".\n"; + + if (before.get ("project") != other->get ("project")) + context.footnote (onProjectChange (before, *other)); + + ++count; + } + } + } + } + } + + context.tdb.commit (); + context.tdb.unlock (); + + if (context.config.getBoolean ("echo.command")) + out << "Appended " << count << " task" << (count == 1 ? ".\n" : "s.\n"); + + output = out.str (); + return rc; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdAppend.h b/src/commands/CmdAppend.h new file mode 100644 index 000000000..ec7ae7990 --- /dev/null +++ b/src/commands/CmdAppend.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_CMDAPPEND +#define INCLUDED_CMDAPPEND +#define L10N // Localization complete. + +#include +#include + +class CmdAppend : public Command +{ +public: + CmdAppend (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 504fb3c45..850972d27 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -96,10 +96,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output) view.set (row, 1, "task log [tags] [attrs] desc..."); view.set (row, 2, "Adds a new task that is already completed."); - row = view.addRow (); - view.set (row, 1, "task append ID [tags] [attrs] desc..."); - view.set (row, 2, "Appends more description to an existing task."); - row = view.addRow (); view.set (row, 1, "task annotate ID desc..."); view.set (row, 2, "Adds an annotation to an existing task."); diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index a4b662e7c..a06e42410 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,7 @@ void Command::factory (std::map & all) { Command* c; + c = new CmdAppend (); all[c->keyword ()] = c; c = new CmdCompletionCommands (); all[c->keyword ()] = c; c = new CmdCompletionIds (); all[c->keyword ()] = c; c = new CmdCompletionProjects (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index 41b7badc4..15334239d 100644 --- a/src/main.h +++ b/src/main.h @@ -52,7 +52,6 @@ bool nag (Task&); // command.cpp int handleAdd (std::string&); int handleLog (std::string&); -int handleAppend (std::string&); int handleDone (std::string&); int handleModify (std::string&); int handleCompletionConfig (std::string&);