Commands - log

- Migrated handleLog to CmdLog.
This commit is contained in:
Paul Beckingham 2011-05-29 21:43:37 -04:00
parent cb613c0691
commit c8eb5df1b2
9 changed files with 160 additions and 76 deletions

View file

@ -143,7 +143,6 @@ void Cmd::load ()
commands.push_back ("done"); commands.push_back ("done");
commands.push_back ("duplicate"); commands.push_back ("duplicate");
commands.push_back ("import"); commands.push_back ("import");
commands.push_back ("log");
commands.push_back ("start"); commands.push_back ("start");
commands.push_back ("stop"); commands.push_back ("stop");
commands.push_back ("summary"); commands.push_back ("summary");
@ -236,7 +235,6 @@ bool Cmd::isWriteCommand ()
command == "done" || command == "done" ||
command == "duplicate" || command == "duplicate" ||
command == "import" || command == "import" ||
command == "log" ||
command == "pull" || command == "pull" ||
command == "start" || command == "start" ||
command == "stop" || command == "stop" ||

View file

@ -252,7 +252,6 @@ int Context::dispatch (std::string &out)
else if (cmd.command == "summary") { rc = handleReportSummary (out); } else if (cmd.command == "summary") { rc = handleReportSummary (out); }
else if (cmd.command == "calendar") { rc = handleReportCalendar (out); } else if (cmd.command == "calendar") { rc = handleReportCalendar (out); }
else if (cmd.command == "timesheet") { rc = handleReportTimesheet (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 == "annotate") { rc = handleAnnotate (out); }
else if (cmd.command == "denotate") { rc = handleDenotate (out); } else if (cmd.command == "denotate") { rc = handleDenotate (out); }
else if (cmd.command == "done") { rc = handleDone (out); } else if (cmd.command == "done") { rc = handleDone (out); }

View file

@ -51,74 +51,6 @@
extern Context context; 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) int handleCompletionConfig (std::string& outs)
{ {

View file

@ -20,6 +20,7 @@ set (commands_SRCS Command.cpp Command.h
CmdIDs.cpp CmdIDs.h CmdIDs.cpp CmdIDs.h
CmdInfo.cpp CmdInfo.h CmdInfo.cpp CmdInfo.h
CmdInstall.cpp CmdInstall.h CmdInstall.cpp CmdInstall.h
CmdLog.cpp CmdLog.h
CmdLogo.cpp CmdLogo.h CmdLogo.cpp CmdLogo.h
CmdPrepend.cpp CmdPrepend.h CmdPrepend.cpp CmdPrepend.h
CmdProjects.cpp CmdProjects.h CmdProjects.cpp CmdProjects.h

View file

@ -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 (); row = view.addRow ();
view.set (row, 1, "task annotate ID desc..."); view.set (row, 1, "task annotate ID desc...");
view.set (row, 2, "Adds an annotation to an existing task."); view.set (row, 2, "Adds an annotation to an existing task.");

115
src/commands/CmdLog.cpp Normal file
View file

@ -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 <sstream>
#include <Context.h>
#include <text.h>
#include <util.h>
#include <main.h>
#include <CmdLog.h>
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;
}
////////////////////////////////////////////////////////////////////////////////

42
src/commands/CmdLog.h Normal file
View file

@ -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 <string>
#include <Command.h>
class CmdLog : public Command
{
public:
CmdLog ();
int execute (const std::string&, std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -42,6 +42,7 @@
#include <CmdIDs.h> #include <CmdIDs.h>
#include <CmdInfo.h> #include <CmdInfo.h>
#include <CmdInstall.h> #include <CmdInstall.h>
#include <CmdLog.h>
#include <CmdLogo.h> #include <CmdLogo.h>
#include <CmdPrepend.h> #include <CmdPrepend.h>
#include <CmdProjects.h> #include <CmdProjects.h>
@ -83,6 +84,7 @@ void Command::factory (std::map <std::string, Command*>& all)
c = new CmdIDs (); all[c->keyword ()] = c; c = new CmdIDs (); all[c->keyword ()] = c;
c = new CmdInfo (); all[c->keyword ()] = c; c = new CmdInfo (); all[c->keyword ()] = c;
c = new CmdInstall (); 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 CmdLogo (); all[c->keyword ()] = c;
c = new CmdPrepend (); all[c->keyword ()] = c; c = new CmdPrepend (); all[c->keyword ()] = c;
c = new CmdProjects (); all[c->keyword ()] = c; c = new CmdProjects (); all[c->keyword ()] = c;

View file

@ -50,7 +50,6 @@ int getDueState (const std::string&);
bool nag (Task&); bool nag (Task&);
// command.cpp // command.cpp
int handleLog (std::string&);
int handleDone (std::string&); int handleDone (std::string&);
int handleModify (std::string&); int handleModify (std::string&);
int handleCompletionConfig (std::string&); int handleCompletionConfig (std::string&);