From e5ae145df2b59cc7ae825f44eaa59289afd51d63 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 2 Aug 2011 00:56:29 -0400 Subject: [PATCH] Command - denotate - Implemented denotate in the new style. --- src/commands/CmdAnnotate.cpp | 2 +- src/commands/CmdDenotate.cpp | 73 +++++++++++++++++++----------------- src/en-US.h | 5 +++ test/denotate.t | 13 +++---- 4 files changed, 51 insertions(+), 42 deletions(-) diff --git a/src/commands/CmdAnnotate.cpp b/src/commands/CmdAnnotate.cpp index 4e8186df9..b7c40b7b7 100644 --- a/src/commands/CmdAnnotate.cpp +++ b/src/commands/CmdAnnotate.cpp @@ -41,7 +41,7 @@ extern Context context; CmdAnnotate::CmdAnnotate () { _keyword = "annotate"; - _usage = "task annotate ID desc..."; + _usage = "task annotate "; _description = STRING_CMD_ANNO_USAGE; _read_only = false; _displays_id = false; diff --git a/src/commands/CmdDenotate.cpp b/src/commands/CmdDenotate.cpp index aca0fa2ae..8b65a8798 100644 --- a/src/commands/CmdDenotate.cpp +++ b/src/commands/CmdDenotate.cpp @@ -25,10 +25,13 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include #include #include +#include #include #include @@ -38,8 +41,8 @@ extern Context context; CmdDenotate::CmdDenotate () { _keyword = "denotate"; - _usage = "task denotate ID desc..."; - _description = "Deletes an annotation from an existing task."; + _usage = "task denotate "; + _description = STRING_CMD_DENO_USAGE; _read_only = false; _displays_id = false; } @@ -48,52 +51,54 @@ CmdDenotate::CmdDenotate () int CmdDenotate::execute (std::string& output) { int rc = 0; - -/* - if (!context.task.has ("description")) - throw std::string ("Description needed to delete an annotation."); - - if (context.sequence.size () == 0) - throw std::string ("A task ID is needed to delete an annotation."); - - bool sensitive = context.config.getBoolean ("search.case.sensitive"); - + int count = 0; std::stringstream out; std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); - Filter filter; - context.tdb.loadPending (tasks, filter); + context.tdb.loadPending (tasks); - context.filter.applySequence (tasks, context.sequence); - if (tasks.size () == 0) + // Apply filter. + std::vector filtered; + filter (tasks, filtered); + + if (filtered.size () == 0) { - context.footnote ("No tasks specified."); + context.footnote (STRING_FEEDBACK_NO_TASKS_SP); return 1; } + bool sensitive = context.config.getBoolean ("search.case.sensitive"); + + // Apply the command line modifications to the completed task. + A3 words = context.a3.extract_modifications (); + if (!words.size ()) + throw std::string (STRING_CMD_DENO_WORDS); + + std::string pattern = words.combine (); + Permission permission; - if (context.sequence.size () > (size_t) context.config.getInteger ("bulk")) + if (filtered.size () > (size_t) context.config.getInteger ("bulk")) permission.bigSequence (); std::vector ::iterator task; - for (task = tasks.begin (); task != tasks.end (); ++task) + for (task = filtered.begin (); task != filtered.end (); ++task) { Task before (*task); - std::string desc = context.task.get ("description"); + std::vector annotations; task->getAnnotations (annotations); if (annotations.size () == 0) - throw std::string ("The specified task has no annotations that can be deleted."); + throw std::string (STRING_CMD_DENO_NONE); std::vector ::iterator i; std::string anno; - bool match = false;; + bool match = false; for (i = annotations.begin (); i != annotations.end (); ++i) { anno = i->value (); - if (anno == desc) + if (anno == pattern) { match = true; annotations.erase (i); @@ -106,11 +111,10 @@ int CmdDenotate::execute (std::string& output) for (i = annotations.begin (); i != annotations.end (); ++i) { anno = i->value (); - std::string::size_type loc = find (anno, desc, sensitive); + std::string::size_type loc = find (anno, pattern, sensitive); if (loc != std::string::npos) { - match = true; annotations.erase (i); task->setAnnotations (annotations); break; @@ -123,26 +127,27 @@ int CmdDenotate::execute (std::string& output) // Only allow valid tasks. task->validate (); - if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?")) + if (permission.confirmed (before, + taskDifferences (before, *task) + STRING_CMD_DONE_PROCEED)) { + ++count; context.tdb.update (*task); if (context.config.getBoolean ("echo.command")) - out << "Found annotation '" - << anno - << "' and deleted it.\n"; + out << format (STRING_CMD_DENO_FOUND, anno) + << "\n"; } } else - out << "Did not find any matching annotation to be deleted for '" - << desc - << "'.\n"; + out << format (STRING_CMD_DENO_NOMATCH, pattern) + << "\n"; } - context.tdb.commit (); + if (count) + context.tdb.commit (); + context.tdb.unlock (); output = out.str (); -*/ return rc; } diff --git a/src/en-US.h b/src/en-US.h index 421a72b34..f7f35fd67 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -303,6 +303,11 @@ #define STRING_CMD_COLUMNS_USAGE "Displays supported columns and styles." #define STRING_CMD_COLUMNS_NOTE "* Means default format, and therefore optional. For example, 'due' and 'due.formatted' are equivalent." #define STRING_CMD_COLUMNS_USAGE2 "Displays only a list of supported columns." +#define STRING_CMD_DENO_USAGE "Deletes an annotation." +#define STRING_CMD_DENO_WORDS "An annotation pattern must be provided." +#define STRING_CMD_DENO_NONE "The specified task has no annotations that can be deleted." +#define STRING_CMD_DENO_FOUND "Found annotation '{1}' and deleted it." +#define STRING_CMD_DENO_NOMATCH "Did not find any matching annotation to be deleted for '{1}'." // Config #define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake." diff --git a/test/denotate.t b/test/denotate.t index a9d2ba851..5157b5e6e 100755 --- a/test/denotate.t +++ b/test/denotate.t @@ -62,16 +62,15 @@ sleep 1; qx{../src/task rc:denotate.rc 1 annotate Kermit and Miss Piggy}; my $output = qx{../src/task rc:denotate.rc rrr}; - like ($output, qr/1 one/, 'task 1'); like ($output, qr/one.+\d{1,2}\/\d{1,2}\/\d{4} Ernie/ms, 'first annotation'); like ($output, qr/Ernie.+\d{1,2}\/\d{1,2}\/\d{4} Bert/ms, 'second annotation'); -like ($output, qr/Bert.+\d{1,2}\/\d{1,2}\/\d{4} Bibo/ms, 'third annotation'); +like ($output, qr/Bert.+\d{1,2}\/\d{1,2}\/\d{4} Bibo/ms, 'third annotation'); # 5 like ($output, qr/Bibo.+\d{1,2}\/\d{1,2}\/\d{4} Kermit the frog/ms, 'fourth annotation'); like ($output, qr/frog.+\d{1,2}\/\d{1,2}\/\d{4} Kermit the frog/ms, 'fifth annotation'); like ($output, qr/frog.+\d{1,2}\/\d{1,2}\/\d{4} Kermit/ms, 'sixth annotation'); like ($output, qr/Kermit.+\d{1,2}\/\d{1,2}\/\d{4} Kermit and Miss Piggy/ms, 'seventh annotation'); -like ($output, qr/1 task/, 'count'); +like ($output, qr/1 task/, 'count'); # 10 qx{../src/task rc:denotate.rc 1 denotate Ernie}; $output = qx{../src/task rc:denotate.rc rrr}; @@ -85,7 +84,7 @@ like ($output, qr/Bert.+\d{1,2}\/\d{1,2}\/\d{4} Kermit the frog/ms, 'Kermit the qx{../src/task rc:denotate.rc 1 denotate BErt}; $output = qx{../src/task rc:denotate.rc rrr}; -like ($output, qr/one.+\d{1,2}\/\d{1,2}\/\d{4} Bert/ms, 'Denotate is case sensitive'); +like ($output, qr/one.+\d{1,2}\/\d{1,2}\/\d{4} Bert/ms, 'Denotate is case sensitive'); # 15 like ($output, qr/Bert.+\d{1,2}\/\d{1,2}\/\d{4} Kermit the frog/ms, 'Kermit the frog still second annoation'); qx{../src/task rc:denotate.rc 1 denotate Kermit}; @@ -93,7 +92,7 @@ $output = qx{../src/task rc:denotate.rc rrr}; like ($output, qr/one.+\d{1,2}\/\d{1,2}\/\d{4} Bert/ms, 'Exact match deletion - Bert'); like ($output, qr/Bert.+\d{1,2}\/\d{1,2}\/\d{4} Kermit the frog/ms, 'Exact match deletion - Kermit the frog'); like ($output, qr/frog.+\d{1,2}\/\d{1,2}\/\d{4} Kermit the frog/ms, 'Exact match deletion - Kermit the frog'); -like ($output, qr/frog.+\d{1,2}\/\d{1,2}\/\d{4} Kermit and Miss Piggy/ms, 'Exact match deletion - Kermit and Miss Piggy'); +like ($output, qr/frog.+\d{1,2}\/\d{1,2}\/\d{4} Kermit and Miss Piggy/ms, 'Exact match deletion - Kermit and Miss Piggy'); # 20 qx{../src/task rc:denotate.rc 1 denotate Kermit the}; $output = qx{../src/task rc:denotate.rc rrr}; @@ -101,10 +100,10 @@ like ($output, qr/one.+\d{1,2}\/\d{1,2}\/\d{4} Bert/ms, 'Delet like ($output, qr/Bert.+\d{1,2}\/\d{1,2}\/\d{4} Kermit the frog/ms, 'Delete just one annotation - Kermit the frog'); like ($output, qr/frog.+\d{1,2}\/\d{1,2}\/\d{4} Kermit and Miss Piggy/ms, 'Delete just one annotation - Kermit and Miss Piggy'); -qx{../src/task rc:denotate.rc 1 denotate Kermit a}; +$output = qx{../src/task rc:denotate.rc 1 denotate Kermit a}; $output = qx{../src/task rc:denotate.rc rrr}; like ($output, qr/one.+\d{1,2}\/\d{1,2}\/\d{4} Bert/ms, 'Delete partial match - Bert'); -like ($output, qr/Bert.+\d{1,2}\/\d{1,2}\/\d{4} Kermit the frog/ms, 'Delete partial match - Kermit the frog'); +like ($output, qr/Bert.+\d{1,2}\/\d{1,2}\/\d{4} Kermit the frog/ms, 'Delete partial match - Kermit the frog'); # 25 unlike ($output, qr/frog.+\d{1,2}\/\d{1,2}\/\d{4} Kermit and Miss Piggy/ms, 'Delete partial match - Kermit and Miss Piggy'); # Cleanup.