Commands - done

- Migrated handleDone to CmdDone.
This commit is contained in:
Paul Beckingham 2011-05-30 13:53:57 -04:00
parent 75a24f5113
commit 908fbd8ca4
9 changed files with 201 additions and 117 deletions

View file

@ -130,7 +130,6 @@ void Cmd::load ()
if (commands.size () == 0) if (commands.size () == 0)
{ {
commands.push_back ("delete"); commands.push_back ("delete");
commands.push_back ("done");
commands.push_back ("merge"); commands.push_back ("merge");
commands.push_back ("push"); commands.push_back ("push");
commands.push_back ("pull"); commands.push_back ("pull");
@ -203,7 +202,6 @@ bool Cmd::isWriteCommand ()
{ {
if (command == "merge" || if (command == "merge" ||
command == "delete" || command == "delete" ||
command == "done" ||
command == "pull") command == "pull")
return true; return true;

View file

@ -249,8 +249,7 @@ int Context::dispatch (std::string &out)
Timer t ("Context::dispatch"); Timer t ("Context::dispatch");
// TODO Chain-of-command pattern dispatch. // TODO Chain-of-command pattern dispatch.
if (cmd.command == "done") { rc = handleDone (out); } if (cmd.command == "delete") { rc = handleDelete (out); }
else if (cmd.command == "delete") { rc = handleDelete (out); }
else if (cmd.command == "merge") { tdb.gc (); else if (cmd.command == "merge") { tdb.gc ();
handleMerge (out); } handleMerge (out); }
else if (cmd.command == "push") { handlePush (out); } else if (cmd.command == "push") { handlePush (out); }

View file

@ -367,114 +367,6 @@ int handleDelete (std::string& outs)
return rc; return rc;
} }
////////////////////////////////////////////////////////////////////////////////
int handleDone (std::string& outs)
{
int rc = 0;
int count = 0;
std::stringstream out;
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter;
context.tdb.loadPending (tasks, filter);
// Filter sequence.
std::vector <Task> 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 ();
bool nagged = false;
foreach (task, tasks)
{
if (task->getStatus () == Task::pending ||
task->getStatus () == Task::waiting)
{
Task before (*task);
// Apply other deltas.
if (deltaDescription (*task))
permission.bigChange ();
deltaTags (*task);
deltaAttributes (*task);
deltaSubstitutions (*task);
// Add an end date.
char entryTime[16];
sprintf (entryTime, "%u", (unsigned int) time (NULL));
task->set ("end", entryTime);
// Change status.
task->setStatus (Task::completed);
// Stop the task, if started.
if (task->has ("start") &&
context.config.getBoolean ("journal.time"))
task->addAnnotation (context.config.get ("journal.time.stop.annotation"));
// Only allow valid tasks.
task->validate ();
if (taskDiff (before, *task))
{
if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?"))
{
context.tdb.update (*task);
if (context.config.getBoolean ("echo.command"))
out << "Completed "
<< task->id
<< " '"
<< task->get ("description")
<< "'.\n";
dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task, false));
++count;
}
}
updateRecurrenceMask (all, *task);
if (!nagged)
nagged = nag (*task);
}
else
{
out << "Task "
<< task->id
<< " '"
<< task->get ("description")
<< "' is neither pending nor waiting.\n";
rc = 1;
}
}
if (count)
context.tdb.commit ();
context.tdb.unlock ();
if (context.config.getBoolean ("echo.command"))
out << "Marked "
<< count
<< " task"
<< (count == 1 ? "" : "s")
<< " as done.\n";
outs = out.str ();
return rc;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int handleModify (std::string& outs) int handleModify (std::string& outs)
{ {

View file

@ -18,6 +18,7 @@ set (commands_SRCS Command.cpp Command.h
CmdCustom.cpp CmdCustom.h CmdCustom.cpp CmdCustom.h
CmdDenotate.cpp CmdDenotate.h CmdDenotate.cpp CmdDenotate.h
CmdDiagnostics.cpp CmdDiagnostics.h CmdDiagnostics.cpp CmdDiagnostics.h
CmdDone.cpp CmdDone.h
CmdDuplicate.cpp CmdDuplicate.h CmdDuplicate.cpp CmdDuplicate.h
CmdEdit.cpp CmdEdit.h CmdEdit.cpp CmdEdit.h
CmdExec.cpp CmdExec.h CmdExec.cpp CmdExec.h

155
src/commands/CmdDone.cpp Normal file
View file

@ -0,0 +1,155 @@
////////////////////////////////////////////////////////////////////////////////
// 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 <CmdDone.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
CmdDone::CmdDone ()
{
_keyword = "done";
_usage = "task done ID [tags] [attrs] [desc...]";
_description = "Marks the specified task as completed.";
_read_only = false;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdDone::execute (const std::string&, std::string& output)
{
int rc = 0;
int count = 0;
std::stringstream out;
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter;
context.tdb.loadPending (tasks, filter);
// Filter sequence.
std::vector <Task> 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 ();
bool nagged = false;
std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
{
if (task->getStatus () == Task::pending ||
task->getStatus () == Task::waiting)
{
Task before (*task);
// Apply other deltas.
if (deltaDescription (*task))
permission.bigChange ();
deltaTags (*task);
deltaAttributes (*task);
deltaSubstitutions (*task);
// Add an end date.
char entryTime[16];
sprintf (entryTime, "%u", (unsigned int) time (NULL));
task->set ("end", entryTime);
// Change status.
task->setStatus (Task::completed);
// Stop the task, if started.
if (task->has ("start") &&
context.config.getBoolean ("journal.time"))
task->addAnnotation (context.config.get ("journal.time.stop.annotation"));
// Only allow valid tasks.
task->validate ();
if (taskDiff (before, *task))
{
if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?"))
{
context.tdb.update (*task);
if (context.config.getBoolean ("echo.command"))
out << "Completed "
<< task->id
<< " '"
<< task->get ("description")
<< "'.\n";
dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task, false));
++count;
}
}
updateRecurrenceMask (all, *task);
if (!nagged)
nagged = nag (*task);
}
else
{
out << "Task "
<< task->id
<< " '"
<< task->get ("description")
<< "' is neither pending nor waiting.\n";
rc = 1;
}
}
if (count)
context.tdb.commit ();
context.tdb.unlock ();
if (context.config.getBoolean ("echo.command"))
out << "Marked "
<< count
<< " task"
<< (count == 1 ? "" : "s")
<< " as done.\n";
output = out.str ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////

42
src/commands/CmdDone.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_CMDDONE
#define INCLUDED_CMDDONE
#define L10N // Localization complete.
#include <string>
#include <Command.h>
class CmdDone : public Command
{
public:
CmdDone ();
int execute (const std::string&, std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -107,10 +107,6 @@ int CmdHelp::execute (const std::string&, std::string& output)
view.set (row, 1, "task delete ID"); view.set (row, 1, "task delete ID");
view.set (row, 2, "Deletes the specified task."); view.set (row, 2, "Deletes the specified task.");
row = view.addRow ();
view.set (row, 1, "task done ID [tags] [attrs] [desc...]");
view.set (row, 2, "Marks the specified task as completed.");
row = view.addRow (); row = view.addRow ();
view.set (row, 1, "task merge URL"); view.set (row, 1, "task merge URL");
view.set (row, 2, "Merges the specified undo.data file with the local data files."); view.set (row, 2, "Merges the specified undo.data file with the local data files.");

View file

@ -40,6 +40,7 @@
#include <CmdCustom.h> #include <CmdCustom.h>
#include <CmdDenotate.h> #include <CmdDenotate.h>
#include <CmdDiagnostics.h> #include <CmdDiagnostics.h>
#include <CmdDone.h>
#include <CmdDuplicate.h> #include <CmdDuplicate.h>
#include <CmdEdit.h> #include <CmdEdit.h>
#include <CmdExec.h> #include <CmdExec.h>
@ -94,6 +95,7 @@ void Command::factory (std::map <std::string, Command*>& all)
c = new CmdCount (); all[c->keyword ()] = c; c = new CmdCount (); all[c->keyword ()] = c;
c = new CmdDenotate (); all[c->keyword ()] = c; c = new CmdDenotate (); all[c->keyword ()] = c;
c = new CmdDiagnostics (); all[c->keyword ()] = c; c = new CmdDiagnostics (); all[c->keyword ()] = c;
c = new CmdDone (); all[c->keyword ()] = c;
c = new CmdDuplicate (); all[c->keyword ()] = c; c = new CmdDuplicate (); all[c->keyword ()] = c;
c = new CmdEdit (); all[c->keyword ()] = c; c = new CmdEdit (); all[c->keyword ()] = c;
c = new CmdExec (); all[c->keyword ()] = c; c = new CmdExec (); 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 handleDone (std::string&);
int handleModify (std::string&); int handleModify (std::string&);
int handleDelete (std::string&); int handleDelete (std::string&);
void handleMerge (std::string&); void handleMerge (std::string&);