Command - append
- Migrated handleAppend to CmdAppend.
This commit is contained in:
@@ -1080,90 +1080,6 @@ int handleModify (std::string& outs)
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleAppend (std::string& outs)
|
||||
{
|
||||
if (!context.task.has ("description"))
|
||||
throw std::string ("Additional text must be provided.");
|
||||
|
||||
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 ();
|
||||
|
||||
foreach (task, tasks)
|
||||
{
|
||||
foreach (other, all)
|
||||
{
|
||||
if (other->id == task->id || // Self
|
||||
(task->has ("parent") &&
|
||||
task->get ("parent") == other->get ("parent")) || // Sibling
|
||||
other->get ("uuid") == task->get ("parent")) // Parent
|
||||
{
|
||||
Task before (*other);
|
||||
|
||||
// A non-zero value forces a file write.
|
||||
int changes = 0;
|
||||
|
||||
// Apply other deltas.
|
||||
changes += deltaAppend (*other);
|
||||
changes += deltaTags (*other);
|
||||
changes += deltaAttributes (*other);
|
||||
changes += deltaSubstitutions (*other);
|
||||
|
||||
if (taskDiff (before, *other))
|
||||
{
|
||||
// Only allow valid tasks.
|
||||
other->validate ();
|
||||
|
||||
if (changes && permission.confirmed (before, taskDifferences (before, *other) + "Proceed with change?"))
|
||||
{
|
||||
context.tdb.update (*other);
|
||||
|
||||
if (context.config.getBoolean ("echo.command"))
|
||||
out << "Appended '"
|
||||
<< context.task.get ("description")
|
||||
<< "' to task "
|
||||
<< other->id
|
||||
<< ".\n";
|
||||
|
||||
if (before.get ("project") != other->get ("project"))
|
||||
context.footnote (onProjectChange (before, *other));
|
||||
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
if (context.config.getBoolean ("echo.command"))
|
||||
out << "Appended " << count << " task" << (count == 1 ? ".\n" : "s.\n");
|
||||
|
||||
outs = out.str ();
|
||||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleDuplicate (std::string& outs)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user