mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-26 15:47:19 +02:00
Enhancement
- Various commands now allow modification and annotation.
This commit is contained in:
parent
b5f04a3ebc
commit
d087bdfd38
9 changed files with 168 additions and 59 deletions
|
@ -63,7 +63,7 @@ int CmdAdd::execute (std::string& output)
|
||||||
|
|
||||||
// Apply the command line modifications to the new task.
|
// Apply the command line modifications to the new task.
|
||||||
Arguments modifications = context.args.extract_modifications ();
|
Arguments modifications = context.args.extract_modifications ();
|
||||||
modify_task (task, modifications);
|
modify_task_description_replace (task, modifications);
|
||||||
apply_defaults (task);
|
apply_defaults (task);
|
||||||
|
|
||||||
// Only valid tasks can be added.
|
// Only valid tasks can be added.
|
||||||
|
|
|
@ -50,14 +50,12 @@ CmdDelete::CmdDelete ()
|
||||||
int CmdDelete::execute (std::string& output)
|
int CmdDelete::execute (std::string& output)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
int count = 0;
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
|
|
||||||
context.disallowModification ();
|
|
||||||
|
|
||||||
std::vector <Task> tasks;
|
std::vector <Task> tasks;
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
context.tdb.loadPending (tasks);
|
context.tdb.loadPending (tasks);
|
||||||
std::vector <Task> all = tasks;
|
|
||||||
|
|
||||||
// Apply filter.
|
// Apply filter.
|
||||||
std::vector <Task> filtered;
|
std::vector <Task> filtered;
|
||||||
|
@ -69,6 +67,9 @@ int CmdDelete::execute (std::string& output)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply the command line modifications to the new task.
|
||||||
|
Arguments modifications = context.args.extract_modifications ();
|
||||||
|
|
||||||
// Determine the end date.
|
// Determine the end date.
|
||||||
char endTime[16];
|
char endTime[16];
|
||||||
sprintf (endTime, "%u", (unsigned int) time (NULL));
|
sprintf (endTime, "%u", (unsigned int) time (NULL));
|
||||||
|
@ -79,6 +80,9 @@ int CmdDelete::execute (std::string& output)
|
||||||
if (task->getStatus () == Task::pending ||
|
if (task->getStatus () == Task::pending ||
|
||||||
task->getStatus () == Task::waiting)
|
task->getStatus () == Task::waiting)
|
||||||
{
|
{
|
||||||
|
modify_task_annotate (*task, modifications);
|
||||||
|
apply_defaults (*task);
|
||||||
|
|
||||||
std::stringstream question;
|
std::stringstream question;
|
||||||
question << "Permanently delete task "
|
question << "Permanently delete task "
|
||||||
<< task->id
|
<< task->id
|
||||||
|
@ -98,7 +102,7 @@ int CmdDelete::execute (std::string& output)
|
||||||
// Scan all pending tasks for siblings of this task, and the parent
|
// Scan all pending tasks for siblings of this task, and the parent
|
||||||
// itself, and delete them.
|
// itself, and delete them.
|
||||||
std::vector <Task>::iterator sibling;
|
std::vector <Task>::iterator sibling;
|
||||||
for (sibling = all.begin (); sibling != all.end (); ++sibling)
|
for (sibling = tasks.begin (); sibling != tasks.end (); ++sibling)
|
||||||
{
|
{
|
||||||
if (sibling->get ("parent") == parent ||
|
if (sibling->get ("parent") == parent ||
|
||||||
sibling->get ("uuid") == parent)
|
sibling->get ("uuid") == parent)
|
||||||
|
@ -110,7 +114,13 @@ int CmdDelete::execute (std::string& output)
|
||||||
if (! sibling->has ("end"))
|
if (! sibling->has ("end"))
|
||||||
sibling->set ("end", endTime);
|
sibling->set ("end", endTime);
|
||||||
|
|
||||||
|
// Apply the command line modifications to the sibling.
|
||||||
|
modify_task_annotate (*sibling, modifications);
|
||||||
|
apply_defaults (*sibling);
|
||||||
|
|
||||||
|
sibling->validate ();
|
||||||
context.tdb.update (*sibling);
|
context.tdb.update (*sibling);
|
||||||
|
++count;
|
||||||
|
|
||||||
if (context.config.getBoolean ("echo.command"))
|
if (context.config.getBoolean ("echo.command"))
|
||||||
out << "Deleting recurring task "
|
out << "Deleting recurring task "
|
||||||
|
@ -125,14 +135,16 @@ int CmdDelete::execute (std::string& output)
|
||||||
{
|
{
|
||||||
// Update mask in parent.
|
// Update mask in parent.
|
||||||
task->setStatus (Task::deleted);
|
task->setStatus (Task::deleted);
|
||||||
updateRecurrenceMask (all, *task);
|
updateRecurrenceMask (tasks, *task);
|
||||||
|
|
||||||
// Don't want a 'delete' to clobber the end date that may have
|
// Don't want a 'delete' to clobber the end date that may have
|
||||||
// been written by a 'done' command.
|
// been written by a 'done' command.
|
||||||
if (! task->has ("end"))
|
if (! task->has ("end"))
|
||||||
task->set ("end", endTime);
|
task->set ("end", endTime);
|
||||||
|
|
||||||
|
task->validate ();
|
||||||
context.tdb.update (*task);
|
context.tdb.update (*task);
|
||||||
|
++count;
|
||||||
|
|
||||||
out << "Deleting recurring task "
|
out << "Deleting recurring task "
|
||||||
<< task->id
|
<< task->id
|
||||||
|
@ -153,7 +165,9 @@ int CmdDelete::execute (std::string& output)
|
||||||
if (! task->has ("end"))
|
if (! task->has ("end"))
|
||||||
task->set ("end", endTime);
|
task->set ("end", endTime);
|
||||||
|
|
||||||
|
task->validate ();
|
||||||
context.tdb.update (*task);
|
context.tdb.update (*task);
|
||||||
|
++count;
|
||||||
|
|
||||||
if (context.config.getBoolean ("echo.command"))
|
if (context.config.getBoolean ("echo.command"))
|
||||||
out << "Deleting task "
|
out << "Deleting task "
|
||||||
|
@ -183,7 +197,9 @@ int CmdDelete::execute (std::string& output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count)
|
||||||
context.tdb.commit ();
|
context.tdb.commit ();
|
||||||
|
|
||||||
context.tdb.unlock ();
|
context.tdb.unlock ();
|
||||||
|
|
||||||
output = out.str ();
|
output = out.str ();
|
||||||
|
|
|
@ -68,6 +68,9 @@ int CmdDone::execute (std::string& output)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply the command line modifications to the completed task.
|
||||||
|
Arguments modifications = context.args.extract_modifications ();
|
||||||
|
|
||||||
Permission permission;
|
Permission permission;
|
||||||
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
||||||
permission.bigSequence ();
|
permission.bigSequence ();
|
||||||
|
@ -81,9 +84,7 @@ int CmdDone::execute (std::string& output)
|
||||||
{
|
{
|
||||||
Task before (*task);
|
Task before (*task);
|
||||||
|
|
||||||
// Apply the command line modifications to the new task.
|
modify_task_annotate (*task, modifications);
|
||||||
Arguments modifications = context.args.extract_modifications ();
|
|
||||||
modify_task (*task, modifications);
|
|
||||||
apply_defaults (*task);
|
apply_defaults (*task);
|
||||||
|
|
||||||
// Add an end date.
|
// Add an end date.
|
||||||
|
|
|
@ -63,7 +63,7 @@ int CmdLog::execute (std::string& output)
|
||||||
|
|
||||||
// Apply the command line modifications to the new task.
|
// Apply the command line modifications to the new task.
|
||||||
Arguments modifications = context.args.extract_modifications ();
|
Arguments modifications = context.args.extract_modifications ();
|
||||||
modify_task (task, modifications);
|
modify_task_description_replace (task, modifications);
|
||||||
apply_defaults (task);
|
apply_defaults (task);
|
||||||
|
|
||||||
// Recurring tasks get a special status.
|
// Recurring tasks get a special status.
|
||||||
|
|
|
@ -27,7 +27,9 @@
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
|
#include <Permission.h>
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
|
#include <i18n.h>
|
||||||
#include <CmdStart.h>
|
#include <CmdStart.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
@ -46,39 +48,58 @@ CmdStart::CmdStart ()
|
||||||
int CmdStart::execute (std::string& output)
|
int CmdStart::execute (std::string& output)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
/*
|
int count = 0;
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
|
|
||||||
context.disallowModification ();
|
|
||||||
|
|
||||||
std::vector <Task> tasks;
|
std::vector <Task> tasks;
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
Filter filter;
|
context.tdb.loadPending (tasks);
|
||||||
context.tdb.loadPending (tasks, filter);
|
|
||||||
|
|
||||||
// Filter sequence.
|
// Apply filter.
|
||||||
context.filter.applySequence (tasks, context.sequence);
|
std::vector <Task> filtered;
|
||||||
if (tasks.size () == 0)
|
filter (tasks, filtered);
|
||||||
|
|
||||||
|
if (filtered.size () == 0)
|
||||||
{
|
{
|
||||||
context.footnote ("No tasks specified.");
|
context.footnote (STRING_FEEDBACK_NO_TASKS_SP);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply the command line modifications to the started task.
|
||||||
|
Arguments modifications = context.args.extract_modifications ();
|
||||||
|
|
||||||
|
Permission permission;
|
||||||
|
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
||||||
|
permission.bigSequence ();
|
||||||
|
|
||||||
bool nagged = false;
|
bool nagged = false;
|
||||||
std::vector <Task>::iterator task;
|
std::vector <Task>::iterator task;
|
||||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||||
{
|
{
|
||||||
if (! task->has ("start"))
|
if (! task->has ("start"))
|
||||||
{
|
{
|
||||||
|
Task before (*task);
|
||||||
|
|
||||||
|
modify_task_annotate (*task, modifications);
|
||||||
|
apply_defaults (*task);
|
||||||
|
|
||||||
|
// Add a start time.
|
||||||
char startTime[16];
|
char startTime[16];
|
||||||
sprintf (startTime, "%u", (unsigned int) time (NULL));
|
sprintf (startTime, "%u", (unsigned int) time (NULL));
|
||||||
|
|
||||||
task->set ("start", startTime);
|
task->set ("start", startTime);
|
||||||
|
|
||||||
if (context.config.getBoolean ("journal.time"))
|
if (context.config.getBoolean ("journal.time"))
|
||||||
task->addAnnotation (context.config.get ("journal.time.start.annotation"));
|
task->addAnnotation (context.config.get ("journal.time.start.annotation"));
|
||||||
|
|
||||||
|
// Only allow valid tasks.
|
||||||
|
task->validate ();
|
||||||
|
|
||||||
|
if (taskDiff (before, *task))
|
||||||
|
{
|
||||||
|
if (permission.confirmed (before, taskDifferences (before, *task) + STRING_CMD_DONE_PROCEED))
|
||||||
|
{
|
||||||
context.tdb.update (*task);
|
context.tdb.update (*task);
|
||||||
|
++count;
|
||||||
|
|
||||||
if (context.config.getBoolean ("echo.command"))
|
if (context.config.getBoolean ("echo.command"))
|
||||||
out << "Started "
|
out << "Started "
|
||||||
|
@ -86,11 +107,14 @@ int CmdStart::execute (std::string& output)
|
||||||
<< " '"
|
<< " '"
|
||||||
<< task->get ("description")
|
<< task->get ("description")
|
||||||
<< "'.\n";
|
<< "'.\n";
|
||||||
if (!nagged)
|
|
||||||
nagged = nag (*task);
|
|
||||||
|
|
||||||
dependencyChainOnStart (*task);
|
dependencyChainOnStart (*task);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nagged)
|
||||||
|
nagged = nag (*task);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out << "Task "
|
out << "Task "
|
||||||
|
@ -102,11 +126,12 @@ int CmdStart::execute (std::string& output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count)
|
||||||
context.tdb.commit ();
|
context.tdb.commit ();
|
||||||
|
|
||||||
context.tdb.unlock ();
|
context.tdb.unlock ();
|
||||||
|
|
||||||
output = out.str ();
|
output = out.str ();
|
||||||
*/
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,9 @@
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
|
#include <Permission.h>
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
|
#include <i18n.h>
|
||||||
#include <CmdStop.h>
|
#include <CmdStop.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
@ -46,35 +48,55 @@ CmdStop::CmdStop ()
|
||||||
int CmdStop::execute (std::string& output)
|
int CmdStop::execute (std::string& output)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
/*
|
int count = 0;
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
|
|
||||||
context.disallowModification ();
|
|
||||||
|
|
||||||
std::vector <Task> tasks;
|
std::vector <Task> tasks;
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
Filter filter;
|
context.tdb.loadPending (tasks);
|
||||||
context.tdb.loadPending (tasks, filter);
|
|
||||||
|
|
||||||
// Filter sequence.
|
// Apply filter.
|
||||||
context.filter.applySequence (tasks, context.sequence);
|
std::vector <Task> filtered;
|
||||||
if (tasks.size () == 0)
|
filter (tasks, filtered);
|
||||||
|
|
||||||
|
if (filtered.size () == 0)
|
||||||
{
|
{
|
||||||
context.footnote ("No tasks specified.");
|
context.footnote (STRING_FEEDBACK_NO_TASKS_SP);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply the command line modifications to the stopped task.
|
||||||
|
Arguments modifications = context.args.extract_modifications ();
|
||||||
|
|
||||||
|
Permission permission;
|
||||||
|
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
||||||
|
permission.bigSequence ();
|
||||||
|
|
||||||
std::vector <Task>::iterator task;
|
std::vector <Task>::iterator task;
|
||||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||||
{
|
{
|
||||||
if (task->has ("start"))
|
if (task->has ("start"))
|
||||||
{
|
{
|
||||||
|
Task before (*task);
|
||||||
|
|
||||||
|
modify_task_annotate (*task, modifications);
|
||||||
|
apply_defaults (*task);
|
||||||
|
|
||||||
|
// Remove the start time.
|
||||||
task->remove ("start");
|
task->remove ("start");
|
||||||
|
|
||||||
if (context.config.getBoolean ("journal.time"))
|
if (context.config.getBoolean ("journal.time"))
|
||||||
task->addAnnotation (context.config.get ("journal.time.stop.annotation"));
|
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) + STRING_CMD_DONE_PROCEED))
|
||||||
|
{
|
||||||
context.tdb.update (*task);
|
context.tdb.update (*task);
|
||||||
|
++count;
|
||||||
|
|
||||||
if (context.config.getBoolean ("echo.command"))
|
if (context.config.getBoolean ("echo.command"))
|
||||||
out << "Stopped "
|
out << "Stopped "
|
||||||
|
@ -83,6 +105,8 @@ int CmdStop::execute (std::string& output)
|
||||||
<< task->get ("description")
|
<< task->get ("description")
|
||||||
<< "'.\n";
|
<< "'.\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out << "Task "
|
out << "Task "
|
||||||
|
@ -94,11 +118,12 @@ int CmdStop::execute (std::string& output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count)
|
||||||
context.tdb.commit ();
|
context.tdb.commit ();
|
||||||
|
|
||||||
context.tdb.unlock ();
|
context.tdb.unlock ();
|
||||||
|
|
||||||
output = out.str ();
|
output = out.str ();
|
||||||
*/
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ CmdUndo::CmdUndo ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdUndo::execute (std::string& output)
|
int CmdUndo::execute (std::string& output)
|
||||||
{
|
{
|
||||||
context.disallowModification ();
|
// TODO Detect attemps to modify the task.
|
||||||
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
context.tdb.undo ();
|
context.tdb.undo ();
|
||||||
|
|
|
@ -285,10 +285,52 @@ void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Apply the modifications in arguments to the task.
|
// Apply the modifications in arguments to the task.
|
||||||
void Command::modify_task (Task& task, Arguments& arguments)
|
void Command::modify_task_description_replace (Task& task, Arguments& arguments)
|
||||||
{
|
{
|
||||||
std::string description;
|
std::string description;
|
||||||
|
modify_task (task, arguments, description);
|
||||||
|
|
||||||
|
if (description.length ())
|
||||||
|
task.set ("description", description);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void Command::modify_task_description_prepend (Task& task, Arguments& arguments)
|
||||||
|
{
|
||||||
|
std::string description;
|
||||||
|
modify_task (task, arguments, description);
|
||||||
|
|
||||||
|
if (description.length ())
|
||||||
|
task.set ("description", description + " " + task.get ("description"));
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void Command::modify_task_description_append (Task& task, Arguments& arguments)
|
||||||
|
{
|
||||||
|
std::string description;
|
||||||
|
modify_task (task, arguments, description);
|
||||||
|
|
||||||
|
if (description.length ())
|
||||||
|
task.set ("description", task.get ("description") + " " + description);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void Command::modify_task_annotate (Task& task, Arguments& arguments)
|
||||||
|
{
|
||||||
|
std::string description;
|
||||||
|
modify_task (task, arguments, description);
|
||||||
|
|
||||||
|
if (description.length ())
|
||||||
|
task.addAnnotation (description);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Worker function that does all the updates, but never overwrites description.
|
||||||
|
void Command::modify_task (
|
||||||
|
Task& task,
|
||||||
|
Arguments& arguments,
|
||||||
|
std::string& description)
|
||||||
|
{
|
||||||
std::vector <Triple>::iterator arg;
|
std::vector <Triple>::iterator arg;
|
||||||
for (arg = arguments.begin (); arg != arguments.end (); ++arg)
|
for (arg = arguments.begin (); arg != arguments.end (); ++arg)
|
||||||
{
|
{
|
||||||
|
@ -370,10 +412,6 @@ void Command::modify_task (Task& task, Arguments& arguments)
|
||||||
else
|
else
|
||||||
throw format (STRING_CMD_MOD_UNEXPECTED, arg->_first);
|
throw format (STRING_CMD_MOD_UNEXPECTED, arg->_first);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only update description if one was specified.
|
|
||||||
if (description.length ())
|
|
||||||
task.set ("description", description);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -54,7 +54,11 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void filter (std::vector <Task>&, std::vector <Task>&);
|
void filter (std::vector <Task>&, std::vector <Task>&);
|
||||||
void modify_task (Task&, Arguments&);
|
void modify_task_description_replace (Task&, Arguments&);
|
||||||
|
void modify_task_description_prepend (Task&, Arguments&);
|
||||||
|
void modify_task_description_append (Task&, Arguments&);
|
||||||
|
void modify_task_annotate (Task&, Arguments&);
|
||||||
|
void modify_task (Task&, Arguments&, std::string&);
|
||||||
void apply_defaults (Task&);
|
void apply_defaults (Task&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue