diff --git a/ChangeLog b/ChangeLog index 201510051..75627f708 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,8 @@ Features + Filter optimization: with no 'OR' or 'XOR' operators, no UUIDS but with IDs the completed.data file is not referenced + Reduced excessive number of sort columns on certain reports + + Similar helper subcommands for 'uuids' as for there is for 'ids' (_uuids and + _zshuuids). Bugs + Fixed bug #954, which caused bulk deletions when using a UUID filter term and diff --git a/doc/man/task.1.in b/doc/man/task.1.in index e402bac6b..340ceb2af 100644 --- a/doc/man/task.1.in +++ b/doc/man/task.1.in @@ -478,6 +478,10 @@ Lists all supported configuration variables, for completion purposes. .B task _ids Shows only the IDs of matching tasks, in the form of a list. +.TP +.B task _uuids +Shows only the UUIDs of matching tasks, in the form of a list. + .TP .B task _projects Shows only a list of all project names used. @@ -502,6 +506,10 @@ Generates a list of all commands, for zsh autocompletion purposes. .B task _zshids Shows the IDs and descriptions of matching tasks. +.TP +.B task _zshuuids +Shows the UUIDs and descriptions of matching tasks. + .SH ATTRIBUTES AND METADATA .TP diff --git a/src/commands/CmdIDs.cpp b/src/commands/CmdIDs.cpp index 3ae6e8111..723534710 100644 --- a/src/commands/CmdIDs.cpp +++ b/src/commands/CmdIDs.cpp @@ -143,7 +143,7 @@ CmdUUIDs::CmdUUIDs () { _keyword = "uuids"; _usage = "task uuids"; - _description = STRING_CMD_UUIDS_USAGE; + _description = STRING_CMD_UUIDS_USAGE_RANGE; _read_only = true; _displays_id = false; } @@ -168,3 +168,63 @@ int CmdUUIDs::execute (std::string& output) } //////////////////////////////////////////////////////////////////////////////// +CmdCompletionUuids::CmdCompletionUuids () +{ + _keyword = "_uuids"; + _usage = "task _uuids"; + _description = STRING_CMD_UUIDS_USAGE_LIST; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdCompletionUuids::execute (std::string& output) +{ + // Apply filter. + handleRecurrence (); + std::vector filtered; + filter (filtered); + context.tdb2.commit (); + + std::vector uuids; + std::vector ::iterator task; + for (task = filtered.begin (); task != filtered.end (); ++task) + uuids.push_back (task->get ("uuid")); + + join (output, "\n", uuids); + output += "\n"; + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +CmdZshCompletionUuids::CmdZshCompletionUuids () +{ + _keyword = "_zshuuids"; + _usage = "task _zshuuids"; + _description = STRING_CMD_UUIDS_USAGE_ZSH; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdZshCompletionUuids::execute (std::string& output) +{ + // Apply filter. + handleRecurrence (); + std::vector filtered; + filter (filtered); + context.tdb2.commit (); + + std::stringstream out; + std::vector ::iterator task; + for (task = filtered.begin (); task != filtered.end (); ++task) + out << task->get ("uuid") + << ":" + << task->get ("description") + << "\n"; + + output = out.str (); + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdIDs.h b/src/commands/CmdIDs.h index 4c7a3915a..624e93a37 100644 --- a/src/commands/CmdIDs.h +++ b/src/commands/CmdIDs.h @@ -60,5 +60,19 @@ public: int execute (std::string&); }; +class CmdCompletionUuids : public Command +{ +public: + CmdCompletionUuids (); + int execute (std::string&); +}; + +class CmdZshCompletionUuids : public Command +{ +public: + CmdZshCompletionUuids (); + int execute (std::string&); +}; + #endif //////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 4e5f73c08..e460cf61c 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -114,6 +114,7 @@ void Command::factory (std::map & all) c = new CmdCompletionCommands (); all[c->keyword ()] = c; c = new CmdCompletionConfig (); all[c->keyword ()] = c; c = new CmdCompletionIds (); all[c->keyword ()] = c; + c = new CmdCompletionUuids (); all[c->keyword ()] = c; c = new CmdCompletionProjects (); all[c->keyword ()] = c; c = new CmdCompletionTags (); all[c->keyword ()] = c; c = new CmdCompletionVersion (); all[c->keyword ()] = c; @@ -162,6 +163,7 @@ void Command::factory (std::map & all) c = new CmdVersion (); all[c->keyword ()] = c; c = new CmdZshCommands (); all[c->keyword ()] = c; c = new CmdZshCompletionIds (); all[c->keyword ()] = c; + c = new CmdZshCompletionUuids (); all[c->keyword ()] = c; // Instantiate a command object for each custom report. std::vector variables; diff --git a/src/en-US.h b/src/en-US.h index b0950ab38..261b3b738 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -220,7 +220,9 @@ #define STRING_CMD_IDS_USAGE_RANGE "Shows the IDs of matching tasks, as a range" #define STRING_CMD_IDS_USAGE_LIST "Shows only the IDs of matching tasks, in the form of a list" #define STRING_CMD_IDS_USAGE_ZSH "Shows the IDs and descriptions of matching tasks" -#define STRING_CMD_UUIDS_USAGE "Shows the UUIDs of matching tasks" +#define STRING_CMD_UUIDS_USAGE_RANGE "Shows the UUIDs of matching tasks, as a comma-separated list" +#define STRING_CMD_UUIDS_USAGE_LIST "Shows the UUIDs of matching tasks, as a list" +#define STRING_CMD_UUIDS_USAGE_ZSH "Shows the UUIDs and descriptions of matching tasks" #define STRING_CMD_EXPORT_USAGE "Exports tasks in JSON format" #define STRING_CMD_INFO_USAGE "Shows all data and metadata" #define STRING_CMD_INFO_BLOCKED "This task blocked by" diff --git a/test/ids.t b/test/ids.t index bfa33206e..9f93e3690 100755 --- a/test/ids.t +++ b/test/ids.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 10; # Create the rc file. if (open my $fh, '>', 'ids.rc') @@ -47,13 +47,29 @@ qx{../src/task rc:ids.rc add four }; qx{../src/task rc:ids.rc add five +A +B}; my $output = qx{../src/task rc:ids.rc ids +A}; -like ($output, qr/^1-3,5$/ms, 'ids +A --> 1-3,5'); +like ($output, qr/^1-3,5$/, 'ids +A --> 1-3,5'); $output = qx{../src/task rc:ids.rc ids +B}; -like ($output, qr/^1,3,5$/ms, 'ids +B --> 1,3,5'); +like ($output, qr/^1,3,5$/, 'ids +B --> 1,3,5'); $output = qx{../src/task rc:ids.rc ids +A -B}; -like ($output, qr/^2$/ms, 'ids +A -B --> 2'); +like ($output, qr/^2$/, 'ids +A -B --> 2'); + +$output = qx{../src/task rc:ids.rc _ids +A}; +like ($output, qr/^1\n2\n3\n5$/, '_ids +A --> 1\n2\n3\n5'); + +$output = qx{../src/task rc:ids.rc _zshids +A}; +like ($output, qr/^1:one\n2:two\n3:three\n5:five$/, '_zshids +A --> 1:one\n2:two\n3:three\n5:five'); + +$output = qx{../src/task rc:ids.rc uuids +A}; +like ($output, qr/^[0-9a-f-]+,[0-9a-f-]+,[0-9a-f-]+,[0-9a-f-]+$/, 'uuids +A --> uuid,uuid,uuid,uuid'); + +$output = qx{../src/task rc:ids.rc _uuids +A}; +like ($output, qr/^[0-9a-f-]+\n[0-9a-f-]+\n[0-9a-f-]+\n[0-9a-f-]+$/, '_uuids +A --> uuid\nuuid\nuuid\nuuid'); + +# The order of the task may not be respected with _zshuuids +$output = qx{../src/task rc:ids.rc _zshuuids +A}; +like ($output, qr/^[0-9a-f-]+:[a-z]+\n[0-9a-f-]+:[a-z]+\n[0-9a-f-]+:[a-z]+\n[0-9a-f-]+:[a-z]+$/, '_zshuuids +A --> uuid:*\nuuid:*\nuuid:*\nuuid:*'); # Cleanup. unlink qw(pending.data completed.data undo.data backlog.data synch.key ids.rc);