Commands - annotate

- Migrated handleAnnotate to CmdAnnotate.
This commit is contained in:
Paul Beckingham 2011-05-30 00:24:48 -04:00
parent c8eb5df1b2
commit f775341fd5
9 changed files with 153 additions and 69 deletions

View file

@ -134,7 +134,6 @@ void Cmd::load ()
commands.push_back ("export.csv"); commands.push_back ("export.csv");
commands.push_back ("export.ical"); commands.push_back ("export.ical");
commands.push_back ("export.yaml"); commands.push_back ("export.yaml");
commands.push_back ("annotate");
commands.push_back ("denotate"); commands.push_back ("denotate");
commands.push_back ("calendar"); commands.push_back ("calendar");
commands.push_back ("colors"); commands.push_back ("colors");
@ -229,7 +228,6 @@ bool Cmd::isReadOnlyCommand ()
bool Cmd::isWriteCommand () bool Cmd::isWriteCommand ()
{ {
if (command == "merge" || if (command == "merge" ||
command == "annotate" ||
command == "denotate" || command == "denotate" ||
command == "delete" || command == "delete" ||
command == "done" || command == "done" ||

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 == "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); }
else if (cmd.command == "delete") { rc = handleDelete (out); } else if (cmd.command == "delete") { rc = handleDelete (out); }

View file

@ -1207,67 +1207,6 @@ int handleColor (std::string& outs)
return rc; return rc;
} }
////////////////////////////////////////////////////////////////////////////////
int handleAnnotate (std::string& outs)
{
int rc = 0;
if (!context.task.has ("description"))
throw std::string ("Cannot apply a blank annotation.");
if (context.sequence.size () == 0)
throw std::string ("ID needed to apply an annotation.");
std::stringstream out;
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter;
context.tdb.loadPending (tasks, filter);
// Filter sequence.
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)
{
Task before (*task);
task->addAnnotation (context.task.get ("description"));
if (taskDiff (before, *task))
{
// Only allow valid tasks.
task->validate ();
if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?"))
{
context.tdb.update (*task);
if (context.config.getBoolean ("echo.command"))
out << "Annotated "
<< task->id
<< " with '"
<< context.task.get ("description")
<< "'.\n";
}
}
}
context.tdb.commit ();
context.tdb.unlock ();
outs = out.str ();
return rc;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int handleDenotate (std::string& outs) int handleDenotate (std::string& outs)
{ {

View file

@ -7,6 +7,7 @@ include_directories (${CMAKE_SOURCE_DIR}
set (commands_SRCS Command.cpp Command.h set (commands_SRCS Command.cpp Command.h
CmdAdd.cpp CmdAdd.h CmdAdd.cpp CmdAdd.h
CmdAnnotate.cpp CmdAnnotate.h
CmdAppend.cpp CmdAppend.h CmdAppend.cpp CmdAppend.h
CmdBurndown.cpp CmdBurndown.h CmdBurndown.cpp CmdBurndown.h
CmdCommands.cpp CmdCommands.h CmdCommands.cpp CmdCommands.h

View file

@ -0,0 +1,108 @@
////////////////////////////////////////////////////////////////////////////////
// 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 <Permission.h>
#include <main.h>
#include <CmdAnnotate.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
CmdAnnotate::CmdAnnotate ()
{
_keyword = "annotate";
_usage = "task annotate ID desc...";
_description = "Adds an annotation to an existing task.";
_read_only = false;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdAnnotate::execute (const std::string&, std::string& output)
{
int rc = 0;
if (!context.task.has ("description"))
throw std::string ("Cannot apply a blank annotation.");
if (context.sequence.size () == 0)
throw std::string ("ID needed to apply an annotation.");
std::stringstream out;
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter;
context.tdb.loadPending (tasks, filter);
// Filter sequence.
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 <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
{
Task before (*task);
task->addAnnotation (context.task.get ("description"));
if (taskDiff (before, *task))
{
// Only allow valid tasks.
task->validate ();
if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?"))
{
context.tdb.update (*task);
if (context.config.getBoolean ("echo.command"))
out << "Annotated "
<< task->id
<< " with '"
<< context.task.get ("description")
<< "'.\n";
}
}
}
context.tdb.commit ();
context.tdb.unlock ();
output = out.str ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////

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_CMDANNOTATE
#define INCLUDED_CMDANNOTATE
#define L10N // Localization complete.
#include <string>
#include <Command.h>
class CmdAnnotate : public Command
{
public:
CmdAnnotate ();
int execute (const std::string&, std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -88,10 +88,6 @@ int CmdHelp::execute (const std::string&, std::string& output)
} }
/* /*
row = view.addRow ();
view.set (row, 1, "task annotate ID desc...");
view.set (row, 2, "Adds an annotation to an existing task.");
row = view.addRow (); row = view.addRow ();
view.set (row, 1, "task denotate ID desc..."); view.set (row, 1, "task denotate ID desc...");
view.set (row, 2, "Deletes an annotation of an existing task."); view.set (row, 2, "Deletes an annotation of an existing task.");

View file

@ -29,6 +29,7 @@
#include <vector> #include <vector>
#include <Command.h> #include <Command.h>
#include <CmdAdd.h> #include <CmdAdd.h>
#include <CmdAnnotate.h>
#include <CmdAppend.h> #include <CmdAppend.h>
#include <CmdBurndown.h> #include <CmdBurndown.h>
#include <CmdCommands.h> #include <CmdCommands.h>
@ -63,6 +64,7 @@ void Command::factory (std::map <std::string, Command*>& all)
Command* c; Command* c;
c = new CmdAdd (); all[c->keyword ()] = c; c = new CmdAdd (); all[c->keyword ()] = c;
c = new CmdAnnotate (); all[c->keyword ()] = c;
c = new CmdAppend (); all[c->keyword ()] = c; c = new CmdAppend (); all[c->keyword ()] = c;
c = new CmdBurndownDaily (); all[c->keyword ()] = c; c = new CmdBurndownDaily (); all[c->keyword ()] = c;
c = new CmdBurndownMonthly (); all[c->keyword ()] = c; c = new CmdBurndownMonthly (); all[c->keyword ()] = c;

View file

@ -59,7 +59,6 @@ int handleDelete (std::string&);
int handleStart (std::string&); int handleStart (std::string&);
int handleStop (std::string&); int handleStop (std::string&);
int handleColor (std::string&); int handleColor (std::string&);
int handleAnnotate (std::string&);
int handleDenotate (std::string&); int handleDenotate (std::string&);
int handleDuplicate (std::string&); int handleDuplicate (std::string&);
void handleUndo (); void handleUndo ();