diff --git a/src/Arguments.cpp b/src/Arguments.cpp index e31bb2aef..3cf145f40 100644 --- a/src/Arguments.cpp +++ b/src/Arguments.cpp @@ -362,6 +362,12 @@ void Arguments::extract_sequence (std::vector & sequence) this->erase (this->begin () + kill[k]); } +//////////////////////////////////////////////////////////////////////////////// +// TODO +void Arguments::extract_nv () +{ +} + //////////////////////////////////////////////////////////////////////////////// // TODO void Arguments::extract_uuids (std::vector & uuids) diff --git a/src/Arguments.h b/src/Arguments.h index 2adea6052..92182b6ca 100644 --- a/src/Arguments.h +++ b/src/Arguments.h @@ -50,6 +50,7 @@ public: bool extract_command (const std::vector &, std::string&); void extract_sequence (std::vector &); + void extract_nv (); void extract_uuids (std::vector &); void extract_filter (); void extract_modifications (); diff --git a/src/Cmd.cpp b/src/Cmd.cpp index d38b09730..bdc58a4ce 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -134,7 +134,6 @@ void Cmd::load () commands.push_back ("export.csv"); commands.push_back ("export.ical"); commands.push_back ("export.yaml"); - commands.push_back ("add"); commands.push_back ("annotate"); commands.push_back ("denotate"); commands.push_back ("calendar"); @@ -231,7 +230,6 @@ bool Cmd::isReadOnlyCommand () bool Cmd::isWriteCommand () { if (command == "merge" || - command == "add" || command == "annotate" || command == "denotate" || command == "delete" || diff --git a/src/Context.cpp b/src/Context.cpp index f74705dce..d0e9f6724 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -252,7 +252,6 @@ int Context::dispatch (std::string &out) else if (cmd.command == "summary") { rc = handleReportSummary (out); } else if (cmd.command == "calendar") { rc = handleReportCalendar (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 == "annotate") { rc = handleAnnotate (out); } else if (cmd.command == "denotate") { rc = handleDenotate (out); } diff --git a/src/command.cpp b/src/command.cpp index 3ad0116c2..eaf077331 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -51,102 +51,6 @@ extern Context context; -//////////////////////////////////////////////////////////////////////////////// -int handleAdd (std::string& outs) -{ - int rc = 0; - std::stringstream out; - - context.task.set ("uuid", uuid ()); - context.task.setEntry (); - - // Recurring tasks get a special status. - if (context.task.has ("due") && - context.task.has ("recur")) - { - context.task.setStatus (Task::recurring); - context.task.set ("mask", ""); - } - - // Tasks with a wait: date get a special status. - else if (context.task.has ("wait")) - context.task.setStatus (Task::waiting); - - // By default, tasks are pending. - else - context.task.setStatus (Task::pending); - - // Override with default.project, if not specified. - if (context.task.get ("project") == "") - context.task.set ("project", context.config.get ("default.project")); - - // Override with default.priority, if not specified. - if (context.task.get ("priority") == "") - { - std::string defaultPriority = context.config.get ("default.priority"); - if (Att::validNameValue ("priority", "", defaultPriority)) - context.task.set ("priority", defaultPriority); - } - - // Override with default.due, if not specified. - if (context.task.get ("due") == "") - { - std::string defaultDue = context.config.get ("default.due"); - if (defaultDue != "" && - Att::validNameValue ("due", "", defaultDue)) - context.task.set ("due", defaultDue); - } - - // Include tags. - foreach (tag, context.tagAdditions) - context.task.addTag (*tag); - - // Must load pending to resolve dependencies, and to provide a new ID. - context.tdb.lock (context.config.getBoolean ("locking")); - - std::vector all; - Filter none; - context.tdb.loadPending (all, none); - - // Resolve dependencies. - if (context.task.has ("depends")) - { - // Convert ID to UUID. - std::vector deps; - split (deps, context.task.get ("depends"), ','); - - // Eliminate the ID-based set. - context.task.set ("depends", ""); - - std::vector ::iterator i; - for (i = deps.begin (); i != deps.end (); i++) - { - int id = atoi (i->c_str ()); - if (id < 0) - context.task.removeDependency (-id); - else - context.task.addDependency (id); - } - } - - // Only valid tasks can be added. - context.task.validate (); - - context.tdb.add (context.task); - -#ifdef FEATURE_NEW_ID - out << "Created task " << context.tdb.nextId () << ".\n"; -#endif - - context.footnote (onProjectChange (context.task)); - - context.tdb.commit (); - context.tdb.unlock (); - - outs = out.str (); - return rc; -} - //////////////////////////////////////////////////////////////////////////////// int handleLog (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 872362656..ce6be24ba 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 + CmdAdd.cpp CmdAdd.h CmdAppend.cpp CmdAppend.h CmdBurndown.cpp CmdBurndown.h CmdCommands.cpp CmdCommands.h diff --git a/src/commands/CmdAdd.cpp b/src/commands/CmdAdd.cpp new file mode 100644 index 000000000..613095411 --- /dev/null +++ b/src/commands/CmdAdd.cpp @@ -0,0 +1,146 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdAdd::CmdAdd () +{ + _keyword = "add"; + _usage = "task add [tags] [attrs] desc..."; + _description = "Adds a new task."; + _read_only = false; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdAdd::execute (const std::string&, std::string& output) +{ + int rc = 0; + std::stringstream out; + + context.task.set ("uuid", uuid ()); + context.task.setEntry (); + + // Recurring tasks get a special status. + if (context.task.has ("due") && + context.task.has ("recur")) + { + context.task.setStatus (Task::recurring); + context.task.set ("mask", ""); + } + + // Tasks with a wait: date get a special status. + else if (context.task.has ("wait")) + context.task.setStatus (Task::waiting); + + // By default, tasks are pending. + else + context.task.setStatus (Task::pending); + + // Override with default.project, if not specified. + if (context.task.get ("project") == "") + context.task.set ("project", context.config.get ("default.project")); + + // Override with default.priority, if not specified. + if (context.task.get ("priority") == "") + { + std::string defaultPriority = context.config.get ("default.priority"); + if (Att::validNameValue ("priority", "", defaultPriority)) + context.task.set ("priority", defaultPriority); + } + + // Override with default.due, if not specified. + if (context.task.get ("due") == "") + { + std::string defaultDue = context.config.get ("default.due"); + if (defaultDue != "" && + Att::validNameValue ("due", "", defaultDue)) + context.task.set ("due", defaultDue); + } + + // Include tags. + std::vector ::iterator tag; + for (tag = context.tagAdditions.begin (); + tag != context.tagAdditions.end (); + ++tag) + context.task.addTag (*tag); + + // Must load pending to resolve dependencies, and to provide a new ID. + context.tdb.lock (context.config.getBoolean ("locking")); + + std::vector all; + Filter none; + context.tdb.loadPending (all, none); + + // Resolve dependencies. + if (context.task.has ("depends")) + { + // Convert ID to UUID. + std::vector deps; + split (deps, context.task.get ("depends"), ','); + + // Eliminate the ID-based set. + context.task.set ("depends", ""); + + std::vector ::iterator i; + for (i = deps.begin (); i != deps.end (); i++) + { + int id = atoi (i->c_str ()); + if (id < 0) + context.task.removeDependency (-id); + else + context.task.addDependency (id); + } + } + + // Only valid tasks can be added. + context.task.validate (); + + context.tdb.add (context.task); + +#ifdef FEATURE_NEW_ID + out << "Created task " << context.tdb.nextId () << ".\n"; +#endif + + context.footnote (onProjectChange (context.task)); + + context.tdb.commit (); + context.tdb.unlock (); + + output = out.str (); + return rc; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdAdd.h b/src/commands/CmdAdd.h new file mode 100644 index 000000000..30bfb597b --- /dev/null +++ b/src/commands/CmdAdd.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_CMDADD +#define INCLUDED_CMDADD +#define L10N // Localization complete. + +#include +#include + +class CmdAdd : public Command +{ +public: + CmdAdd (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 44a5f2e7b..a2bf0ba28 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -88,10 +88,6 @@ int CmdHelp::execute (const std::string&, std::string& output) } /* - row = view.addRow (); - view.set (row, 1, "task add [tags] [attrs] desc..."); - view.set (row, 2, "Adds a new task."); - row = view.addRow (); view.set (row, 1, "task log [tags] [attrs] desc..."); view.set (row, 2, "Adds a new task that is already completed."); diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 171ddc055..52042c1c5 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,7 @@ void Command::factory (std::map & all) { Command* c; + c = new CmdAdd (); all[c->keyword ()] = c; c = new CmdAppend (); all[c->keyword ()] = c; c = new CmdBurndownDaily (); all[c->keyword ()] = c; c = new CmdBurndownMonthly (); all[c->keyword ()] = c; diff --git a/src/import.cpp b/src/import.cpp index 7aaed6e7b..ddac0a6f3 100644 --- a/src/import.cpp +++ b/src/import.cpp @@ -705,7 +705,8 @@ static std::string importTaskCmdLine (const std::vector & lines) context.task.clear (); context.cmd.command = ""; context.parse (); - (void)handleAdd (unused); +// (void)handleAdd (unused); + context.commands["add"]->execute (unused, unused); context.clearMessages (); } diff --git a/src/main.h b/src/main.h index fbb269402..7f3f837bd 100644 --- a/src/main.h +++ b/src/main.h @@ -50,7 +50,6 @@ int getDueState (const std::string&); bool nag (Task&); // command.cpp -int handleAdd (std::string&); int handleLog (std::string&); int handleDone (std::string&); int handleModify (std::string&);