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

@ -18,6 +18,7 @@ set (commands_SRCS Command.cpp Command.h
CmdCustom.cpp CmdCustom.h
CmdDenotate.cpp CmdDenotate.h
CmdDiagnostics.cpp CmdDiagnostics.h
CmdDone.cpp CmdDone.h
CmdDuplicate.cpp CmdDuplicate.h
CmdEdit.cpp CmdEdit.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, 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 ();
view.set (row, 1, "task merge URL");
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 <CmdDenotate.h>
#include <CmdDiagnostics.h>
#include <CmdDone.h>
#include <CmdDuplicate.h>
#include <CmdEdit.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 CmdDenotate (); 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 CmdEdit (); all[c->keyword ()] = c;
c = new CmdExec (); all[c->keyword ()] = c;