From c8eb5df1b20467a1668162cb310e64770d7d962c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 29 May 2011 21:43:37 -0400 Subject: [PATCH] Commands - log - Migrated handleLog to CmdLog. --- src/Cmd.cpp | 2 - src/Context.cpp | 1 - src/command.cpp | 68 --------------------- src/commands/CMakeLists.txt | 1 + src/commands/CmdHelp.cpp | 4 -- src/commands/CmdLog.cpp | 115 ++++++++++++++++++++++++++++++++++++ src/commands/CmdLog.h | 42 +++++++++++++ src/commands/Command.cpp | 2 + src/main.h | 1 - 9 files changed, 160 insertions(+), 76 deletions(-) create mode 100644 src/commands/CmdLog.cpp create mode 100644 src/commands/CmdLog.h diff --git a/src/Cmd.cpp b/src/Cmd.cpp index bdc58a4ce..0f7b5b22e 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -143,7 +143,6 @@ void Cmd::load () commands.push_back ("done"); commands.push_back ("duplicate"); commands.push_back ("import"); - commands.push_back ("log"); commands.push_back ("start"); commands.push_back ("stop"); commands.push_back ("summary"); @@ -236,7 +235,6 @@ bool Cmd::isWriteCommand () command == "done" || command == "duplicate" || command == "import" || - command == "log" || command == "pull" || command == "start" || command == "stop" || diff --git a/src/Context.cpp b/src/Context.cpp index d0e9f6724..424f77537 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 == "log") { rc = handleLog (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 eaf077331..5f62078c5 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -51,74 +51,6 @@ extern Context context; -//////////////////////////////////////////////////////////////////////////////// -int handleLog (std::string& outs) -{ - int rc = 0; - std::stringstream out; - - context.task.setStatus (Task::completed); - context.task.set ("uuid", uuid ()); - context.task.setEntry (); - - // Add an end date. - char entryTime[16]; - sprintf (entryTime, "%u", (unsigned int) time (NULL)); - context.task.set ("end", entryTime); - - // Recurring tasks get a special status. - if (context.task.has ("recur")) - throw std::string ("You cannot log recurring tasks."); - - if (context.task.has ("wait")) - throw std::string ("You cannot log waiting tasks."); - - // It makes no sense to add dependencies to an already-completed task. - if (context.task.get ("depends") != "") - throw std::string ("You cannot specify dependencies on a completed task."); - - // 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); - - // Only valid tasks can be added. - context.task.validate (); - - context.tdb.lock (context.config.getBoolean ("locking")); - context.tdb.add (context.task); - context.tdb.commit (); - - if (context.config.getBoolean ("echo.command")) - out << "Logged task.\n"; - - context.footnote (onProjectChange (context.task)); - context.tdb.unlock (); - - outs = out.str (); - return rc; -} - //////////////////////////////////////////////////////////////////////////////// int handleCompletionConfig (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index ce6be24ba..79737161b 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -20,6 +20,7 @@ set (commands_SRCS Command.cpp Command.h CmdIDs.cpp CmdIDs.h CmdInfo.cpp CmdInfo.h CmdInstall.cpp CmdInstall.h + CmdLog.cpp CmdLog.h CmdLogo.cpp CmdLogo.h CmdPrepend.cpp CmdPrepend.h CmdProjects.cpp CmdProjects.h diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index a2bf0ba28..24a6b1764 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 log [tags] [attrs] desc..."); - view.set (row, 2, "Adds a new task that is already completed."); - 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/CmdLog.cpp b/src/commands/CmdLog.cpp new file mode 100644 index 000000000..72c33d88f --- /dev/null +++ b/src/commands/CmdLog.cpp @@ -0,0 +1,115 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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; + +//////////////////////////////////////////////////////////////////////////////// +CmdLog::CmdLog () +{ + _keyword = "log"; + _usage = "task log [tags] [attrs] desc..."; + _description = "Adds a new task that is already completed."; + _read_only = false; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdLog::execute (const std::string&, std::string& output) +{ + int rc = 0; + std::stringstream out; + + context.task.setStatus (Task::completed); + context.task.set ("uuid", uuid ()); + context.task.setEntry (); + + // Add an end date. + char entryTime[16]; + sprintf (entryTime, "%u", (unsigned int) time (NULL)); + context.task.set ("end", entryTime); + + // Recurring tasks get a special status. + if (context.task.has ("recur")) + throw std::string ("You cannot log recurring tasks."); + + if (context.task.has ("wait")) + throw std::string ("You cannot log waiting tasks."); + + // It makes no sense to add dependencies to an already-completed task. + if (context.task.get ("depends") != "") + throw std::string ("You cannot specify dependencies on a completed task."); + + // 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); + + // Only valid tasks can be added. + context.task.validate (); + + context.tdb.lock (context.config.getBoolean ("locking")); + context.tdb.add (context.task); + context.tdb.commit (); + + if (context.config.getBoolean ("echo.command")) + out << "Logged task.\n"; + + context.footnote (onProjectChange (context.task)); + context.tdb.unlock (); + + output = out.str (); + return rc; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdLog.h b/src/commands/CmdLog.h new file mode 100644 index 000000000..35700dee9 --- /dev/null +++ b/src/commands/CmdLog.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_CMDLOG +#define INCLUDED_CMDLOG +#define L10N // Localization complete. + +#include +#include + +class CmdLog : public Command +{ +public: + CmdLog (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 52042c1c5..e9fd13d3a 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -83,6 +84,7 @@ void Command::factory (std::map & all) c = new CmdIDs (); all[c->keyword ()] = c; c = new CmdInfo (); all[c->keyword ()] = c; c = new CmdInstall (); all[c->keyword ()] = c; + c = new CmdLog (); all[c->keyword ()] = c; c = new CmdLogo (); all[c->keyword ()] = c; c = new CmdPrepend (); all[c->keyword ()] = c; c = new CmdProjects (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index 7f3f837bd..874168135 100644 --- a/src/main.h +++ b/src/main.h @@ -50,7 +50,6 @@ int getDueState (const std::string&); bool nag (Task&); // command.cpp -int handleLog (std::string&); int handleDone (std::string&); int handleModify (std::string&); int handleCompletionConfig (std::string&);