Commands - done

- The 'done' command now functional.
- Localized CmdDone.cpp.
This commit is contained in:
Paul Beckingham 2011-06-26 23:28:21 -04:00
parent 1b90adc1aa
commit 877ecbc864
6 changed files with 54 additions and 48 deletions

View file

@ -881,10 +881,14 @@ void Task::substitute (
void Task::validate () const void Task::validate () const
{ {
// Every task needs an ID, entry and description attribute. // Every task needs an ID, entry and description attribute.
if (!has ("uuid") || if (!has ("uuid"))
!has ("entry") || throw std::string ("A task must have a UUID.");
!has ("description"))
throw std::string ("A task must have a description in order to be valid."); if (!has ("entry"))
throw std::string ("A task must have an entry timestamp.");
if (!has ("description"))
throw std::string ("A task must have a description.");
if (get ("description") == "") // No i18n if (get ("description") == "") // No i18n
throw std::string ("Cannot add a task that is blank, or contains <CR> or <LF> characters."); throw std::string ("Cannot add a task that is blank, or contains <CR> or <LF> characters.");

View file

@ -25,10 +25,14 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <sstream> #include <sstream>
#include <Context.h> #include <Context.h>
#include <Permission.h> #include <Permission.h>
#include <main.h> #include <main.h>
#include <text.h>
#include <i18n.h>
#include <CmdDone.h> #include <CmdDone.h>
extern Context context; extern Context context;
@ -38,7 +42,7 @@ CmdDone::CmdDone ()
{ {
_keyword = "done"; _keyword = "done";
_usage = "task done ID [tags] [attrs] [desc...]"; _usage = "task done ID [tags] [attrs] [desc...]";
_description = "Marks the specified task as completed."; _description = STRING_CMD_DONE_USAGE;
_read_only = false; _read_only = false;
_displays_id = false; _displays_id = false;
} }
@ -47,44 +51,40 @@ CmdDone::CmdDone ()
int CmdDone::execute (std::string& output) int CmdDone::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
/*
int count = 0; int count = 0;
std::stringstream out; std::stringstream out;
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.
std::vector <Task> all = tasks; std::vector <Task> filtered;
context.filter.applySequence (tasks, context.sequence); filter (tasks, filtered);
if (tasks.size () == 0)
if (filtered.size () == 0)
{ {
context.footnote ("No tasks specified."); context.footnote (STRING_FEEDBACK_NO_TASKS_SP);
return 1; return 1;
} }
Permission permission; Permission permission;
if (context.sequence.size () > (size_t) context.config.getInteger ("bulk")) if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
permission.bigSequence (); 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->getStatus () == Task::pending || if (task->getStatus () == Task::pending ||
task->getStatus () == Task::waiting) task->getStatus () == Task::waiting)
{ {
Task before (*task); Task before (*task);
// Apply other deltas. // Apply the command line modifications to the new task.
if (deltaDescription (*task)) Arguments modifications = context.args.extract_modifications ();
permission.bigChange (); modify_task (*task, modifications);
apply_defaults (*task);
deltaTags (*task);
deltaAttributes (*task);
deltaSubstitutions (*task);
// Add an end date. // Add an end date.
char entryTime[16]; char entryTime[16];
@ -104,16 +104,13 @@ int CmdDone::execute (std::string& output)
if (taskDiff (before, *task)) if (taskDiff (before, *task))
{ {
if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?")) if (permission.confirmed (before, taskDifferences (before, *task) + STRING_CMD_DONE_PROCEED))
{ {
context.tdb.update (*task); context.tdb.update (*task);
if (context.config.getBoolean ("echo.command")) if (context.config.getBoolean ("echo.command"))
out << "Completed " out << format (STRING_CMD_DONE_COMPLETED, task->id, task->get ("description"))
<< task->id << "\n";
<< " '"
<< task->get ("description")
<< "'.\n";
dependencyChainOnComplete (*task); dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task, false)); context.footnote (onProjectChange (*task, false));
@ -122,17 +119,14 @@ int CmdDone::execute (std::string& output)
} }
} }
updateRecurrenceMask (all, *task); updateRecurrenceMask (filtered, *task);
if (!nagged) if (!nagged)
nagged = nag (*task); nagged = nag (*task);
} }
else else
{ {
out << "Task " out << format (STRING_CMD_DONE_NOT_PENDING, task->id, task->get ("description"))
<< task->id << "\n";
<< " '"
<< task->get ("description")
<< "' is neither pending nor waiting.\n";
rc = 1; rc = 1;
} }
} }
@ -143,14 +137,14 @@ int CmdDone::execute (std::string& output)
context.tdb.unlock (); context.tdb.unlock ();
if (context.config.getBoolean ("echo.command")) if (context.config.getBoolean ("echo.command"))
out << "Marked " if (count == 1)
<< count out << format (STRING_CMD_DONE_MARKED, count)
<< " task" << "\n";
<< (count == 1 ? "" : "s") else
<< " as done.\n"; out << format (STRING_CMD_DONE_MARKED_N, count)
<< "\n";
output = out.str (); output = out.str ();
*/
return rc; return rc;
} }

View file

@ -190,7 +190,7 @@ int CmdHistoryMonthly::execute (std::string& output)
<< "\n"; << "\n";
else else
{ {
out << STRING_CMD_HISTORY_NO_TASKS << "\n"; out << STRING_FEEDBACK_NO_TASKS << "\n";
rc = 1; rc = 1;
} }
@ -347,7 +347,7 @@ int CmdHistoryAnnual::execute (std::string& output)
<< "\n"; << "\n";
else else
{ {
out << STRING_CMD_HISTORY_NO_TASKS << "\n"; out << STRING_FEEDBACK_NO_TASKS << "\n";
rc = 1; rc = 1;
} }
@ -546,7 +546,7 @@ int CmdGHistoryMonthly::execute (std::string& output)
} }
else else
{ {
out << STRING_CMD_HISTORY_NO_TASKS << "\n"; out << STRING_FEEDBACK_NO_TASKS << "\n";
rc = 1; rc = 1;
} }
@ -742,7 +742,7 @@ int CmdGHistoryAnnual::execute (std::string& output)
} }
else else
{ {
out << STRING_CMD_HISTORY_NO_TASKS << "\n"; out << STRING_FEEDBACK_NO_TASKS << "\n";
rc = 1; rc = 1;
} }

View file

@ -64,7 +64,7 @@ int CmdUrgency::execute (std::string& output)
if (filtered.size () == 0) if (filtered.size () == 0)
{ {
context.footnote (STRING_CMD_URGENCY_NO_TASKS); context.footnote (STRING_FEEDBACK_NO_TASKS_SP);
return 1; return 1;
} }

View file

@ -360,6 +360,8 @@ void Command::modify_task (Task& task, Arguments& arguments)
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); task.set ("description", description);
} }

View file

@ -169,7 +169,6 @@
#define STRING_CMD_LOGO_COLOR_REQ "The logo command requires that color support is enabled." #define STRING_CMD_LOGO_COLOR_REQ "The logo command requires that color support is enabled."
#define STRING_CMD_EXEC_USAGE "Executes external commands and scripts" #define STRING_CMD_EXEC_USAGE "Executes external commands and scripts"
#define STRING_CMD_URGENCY_USAGE "Displays the urgency measure of a task." #define STRING_CMD_URGENCY_USAGE "Displays the urgency measure of a task."
#define STRING_CMD_URGENCY_NO_TASKS "No tasks specified."
#define STRING_CMD_URGENCY_RESULT "task {1} urgency {2}" #define STRING_CMD_URGENCY_RESULT "task {1} urgency {2}"
#define STRING_CMD_ADD_USAGE "Adds a new task." #define STRING_CMD_ADD_USAGE "Adds a new task."
#define STRING_CMD_ADD_FEEDBACK "Created task {1}." #define STRING_CMD_ADD_FEEDBACK "Created task {1}."
@ -222,7 +221,6 @@
#define STRING_CMD_HISTORY_DEL "Deleted" #define STRING_CMD_HISTORY_DEL "Deleted"
#define STRING_CMD_HISTORY_NET "Net" #define STRING_CMD_HISTORY_NET "Net"
#define STRING_CMD_HISTORY_USAGE_A "Shows a report of task history, by year." #define STRING_CMD_HISTORY_USAGE_A "Shows a report of task history, by year."
#define STRING_CMD_HISTORY_NO_TASKS "No tasks."
#define STRING_CMD_HISTORY_AVERAGE "Average" #define STRING_CMD_HISTORY_AVERAGE "Average"
#define STRING_CMD_HISTORY_LEGEND "Legend: {1}, {2}, {3}" #define STRING_CMD_HISTORY_LEGEND "Legend: {1}, {2}, {3}"
#define STRING_CMD_HISTORY_LEGEND_A "Legend: + added, X completed, - deleted" #define STRING_CMD_HISTORY_LEGEND_A "Legend: + added, X completed, - deleted"
@ -231,6 +229,12 @@
#define STRING_CMD_GHISTORY_YEAR "Year" #define STRING_CMD_GHISTORY_YEAR "Year"
#define STRING_CMD_GHISTORY_MONTH "Month" #define STRING_CMD_GHISTORY_MONTH "Month"
#define STRING_CMD_GHISTORY_NUMBER "Number Added/Completed/Deleted" #define STRING_CMD_GHISTORY_NUMBER "Number Added/Completed/Deleted"
#define STRING_CMD_DONE_USAGE "Marks the specified task as completed."
#define STRING_CMD_DONE_PROCEED "Proceed with change?"
#define STRING_CMD_DONE_COMPLETED "Completed {1} '{2}'."
#define STRING_CMD_DONE_NOT_PENDING "Task {1} '{2}' is neither pending nor waiting."
#define STRING_CMD_DONE_MARKED "Marked {1} task as done"
#define STRING_CMD_DONE_MARKED_N "Marked {1} tasks as done"
// Config // Config
#define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake." #define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake."
@ -272,6 +276,8 @@
#define STRING_INFINITE_LOOP "Terminated substitution because more than {1} changes were made - infinite loop protection." #define STRING_INFINITE_LOOP "Terminated substitution because more than {1} changes were made - infinite loop protection."
// Feedback // Feedback
#define STRING_FEEDBACK_NO_TASKS "No tasks."
#define STRING_FEEDBACK_NO_TASKS_SP "No tasks specified."
#define STRING_FEEDBACK_NO_MATCH "No matches." #define STRING_FEEDBACK_NO_MATCH "No matches."
#define STRING_FEEDBACK_TASKS_SINGLE "(1 task)" #define STRING_FEEDBACK_TASKS_SINGLE "(1 task)"
#define STRING_FEEDBACK_TASKS_PLURAL "({1} tasks)" #define STRING_FEEDBACK_TASKS_PLURAL "({1} tasks)"