Commands - done
- Migrated handleDone to CmdDone.
This commit is contained in:
108
src/command.cpp
108
src/command.cpp
@@ -367,114 +367,6 @@ int handleDelete (std::string& outs)
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user