mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Command - prepend
- Migrated handlePrepend to CmdPrepend.
This commit is contained in:
parent
920e1c6c86
commit
ef65617258
9 changed files with 177 additions and 92 deletions
|
@ -1164,90 +1164,6 @@ int handleAppend (std::string& outs)
|
|||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handlePrepend (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 += deltaPrepend (*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) + "Are you sure?"))
|
||||
{
|
||||
context.tdb.update (*other);
|
||||
|
||||
if (context.config.getBoolean ("echo.command"))
|
||||
out << "Prepended '"
|
||||
<< 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 << "Prepended " << count << " task" << (count == 1 ? ".\n" : "s.\n");
|
||||
|
||||
outs = out.str ();
|
||||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleDuplicate (std::string& outs)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue