From b63bd9e9851838df367f665fd5ba0fa5befa0853 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 28 May 2012 16:06:33 -0400 Subject: [PATCH] Feature #921 - Feature #921, which implements a 'udas' command that describes defined UDAs, and a '_udas' for completion purposes. --- ChangeLog | 2 + NEWS | 2 + doc/man/task.1.in | 8 ++ src/commands/CMakeLists.txt | 1 + src/commands/CmdUDAs.cpp | 157 ++++++++++++++++++++++++++++++++++++ src/commands/CmdUDAs.h | 50 ++++++++++++ src/commands/Command.cpp | 3 + src/en-US.h | 9 +++ 8 files changed, 232 insertions(+) create mode 100644 src/commands/CmdUDAs.cpp create mode 100644 src/commands/CmdUDAs.h diff --git a/ChangeLog b/ChangeLog index 9f58b0dd8..eee227f56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ Features expire and are deleted. + Feature #516, which allows the duplication of completed tasks (thanks to Peter De Poorter, Ethan Schoonover). + + Feature #921, which implements a 'udas' command that describes defined UDAs, + and a '_udas' for completion purposes. + Applied patch for feature #1005, which prevents the update-holidays.pl script from creating duplicate holidays (thanks to Jörg Plate). + Added the new 'indented' format for the 'project' attribute. diff --git a/NEWS b/NEWS index d5796568b..2173b7717 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,8 @@ New Features in taskwarrior 2.0.1 New commands in taskwarrior 2.0.1 - New 'ready' report that lists tasks ready for work, sorted by urgency. + - New 'udas' command shows UDA details. + - New '_udas' helper command lists UDA names for completion purposes. New configuration options in taskwarrior 2.0.1 diff --git a/doc/man/task.1.in b/doc/man/task.1.in index e6afbdc10..5c057fd13 100644 --- a/doc/man/task.1.in +++ b/doc/man/task.1.in @@ -225,6 +225,10 @@ filter, then makes each of those tasks pending again. This command is mainly of use to external scripts. As such, only minimal output is generated (equivalent to verbose=nothing). +.TP +.B task udas +Shows a list of UDAs that are defined, including their name, type and label. + .TP .B task information Shows all data and metadata for the specified tasks. This is the only means of @@ -487,6 +491,10 @@ Shows only the IDs of matching tasks, in the form of a list. Shows only the UUIDs of matching tasks among all tasks (even deleted and completed tasks), in the form of a list. +.TP +.B task _udas +Shows only defined UDA names, in the form of a list. + .TP .B task _projects Shows only a list of all project names used. diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index d2ff29a93..bf7c8beff 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -48,6 +48,7 @@ set (commands_SRCS Command.cpp Command.h CmdSynch.cpp CmdSynch.h CmdTags.cpp CmdTags.h CmdTimesheet.cpp CmdTimesheet.h + CmdUDAs.cpp CmdUDAs.h CmdUndo.cpp CmdUndo.h CmdUrgency.cpp CmdUrgency.h CmdVersion.cpp CmdVersion.h) diff --git a/src/commands/CmdUDAs.cpp b/src/commands/CmdUDAs.cpp new file mode 100644 index 000000000..35c01a7d5 --- /dev/null +++ b/src/commands/CmdUDAs.cpp @@ -0,0 +1,157 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006-2012, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#define L10N // Localization complete. + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdUDAs::CmdUDAs () +{ + _keyword = "udas"; + _usage = "task udas"; + _description = STRING_CMD_UDAS_USAGE; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdUDAs::execute (std::string& output) +{ + int rc = 0; + std::stringstream out; + + std::vector names; + context.config.all (names); + + std::vector udas; + std::vector ::iterator name; + for (name = names.begin (); name != names.end (); ++name) + { + if (name->substr (0, 4) == "uda." && + name->find (".type") != std::string::npos) + { + std::string::size_type period = name->find ('.', 4); + if (period != std::string::npos) + udas.push_back (name->substr (4, period - 4)); + } + } + + if (udas.size ()) + { + std::sort (udas.begin (), udas.end ()); + + // Render a list of UDA name, type and label. + ViewText view; + view.width (context.getWidth ()); + view.add (Column::factory ("string", STRING_COLUMN_LABEL_UDA)); + view.add (Column::factory ("string", STRING_COLUMN_LABEL_TYPE)); + view.add (Column::factory ("string", STRING_COLUMN_LABEL_LABEL)); + + + std::vector ::iterator uda; + for (uda = udas.begin (); uda != udas.end (); ++uda) + { + std::string type = context.config.get ("uda." + *uda + ".type"); + std::string label = context.config.get ("uda." + *uda + ".label"); + if (label == "") + label = *uda; + + int row = view.addRow (); + view.set (row, 0, *uda); + view.set (row, 1, type); + view.set (row, 2, label); + } + + out << optionalBlankLine () + << view.render () + << optionalBlankLine () + << (udas.size () == 1 + ? format (STRING_CMD_UDAS_SUMMARY, udas.size ()) + : format (STRING_CMD_UDAS_SUMMARY2, udas.size ())) + << "\n"; + } + else + { + out << STRING_CMD_UDAS_NO << "\n"; + rc = 1; + } + + output = out.str (); + return rc; +} + +/////////////////////////////////////////////////////////////////////////////// +CmdCompletionUDAs::CmdCompletionUDAs () +{ + _keyword = "_udas"; + _usage = "task _udas"; + _description = STRING_CMD_UDAS_COMPL_USAGE; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdCompletionUDAs::execute (std::string& output) +{ + std::vector names; + context.config.all (names); + + std::vector udas; + std::vector ::iterator name; + for (name = names.begin (); name != names.end (); ++name) + { + if (name->substr (0, 4) == "uda." && + name->find (".type") != std::string::npos) + { + std::string::size_type period = name->find ('.', 4); + if (period != std::string::npos) + udas.push_back (name->substr (4, period - 4)); + } + } + + if (udas.size ()) + { + std::sort (udas.begin (), udas.end ()); + join (output, "\n", udas); + output += "\n"; + } + + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdUDAs.h b/src/commands/CmdUDAs.h new file mode 100644 index 000000000..265bef51c --- /dev/null +++ b/src/commands/CmdUDAs.h @@ -0,0 +1,50 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006-2012, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_CMDUDAS +#define INCLUDED_CMDUDAS +#define L10N // Localization complete. + +#include +#include + +class CmdUDAs : public Command +{ +public: + CmdUDAs (); + int execute (std::string&); +}; + +class CmdCompletionUDAs : public Command +{ +public: + CmdCompletionUDAs (); + int execute (std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index e460cf61c..cc29f234a 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -85,6 +85,7 @@ //#include #include #include +#include #include #include #include @@ -114,6 +115,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 CmdCompletionUDAs (); 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; @@ -157,6 +159,7 @@ void Command::factory (std::map & all) // c = new CmdSynch (); all[c->keyword ()] = c; c = new CmdTags (); all[c->keyword ()] = c; c = new CmdTimesheet (); all[c->keyword ()] = c; + c = new CmdUDAs (); all[c->keyword ()] = c; c = new CmdUndo (); all[c->keyword ()] = c; c = new CmdUrgency (); all[c->keyword ()] = c; c = new CmdUUIDs (); all[c->keyword ()] = c; diff --git a/src/en-US.h b/src/en-US.h index e9a2754c8..c87a6c4c5 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -183,6 +183,9 @@ #define STRING_COLUMN_LABEL_STYLES "Supported Formats" #define STRING_COLUMN_LABEL_EXAMPLES "Example" #define STRING_COLUMN_LABEL_SCHED "Scheduled" +#define STRING_COLUMN_LABEL_UDA "Name" +#define STRING_COLUMN_LABEL_TYPE "Type" +#define STRING_COLUMN_LABEL_LABEL "Label" // Column Examples #define STRING_COLUMN_EXAMPLES_TAGS "home @chore" @@ -220,6 +223,8 @@ #define STRING_CMD_IDS_USAGE_RANGE "Shows the IDs of matching tasks, as a range" #define STRING_CMD_IDS_USAGE_LIST "Shows 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_UDAS_USAGE "Shows all the defined UDA details" +#define STRING_CMD_UDAS_COMPL_USAGE "Shows the defined UDAs for completion purposes" #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" @@ -306,6 +311,10 @@ #define STRING_CMD_SUMMARY_NONE "(none)" #define STRING_CMD_COUNT_USAGE "Counts matching tasks" +#define STRING_CMD_UDAS_NO "No UDAs defined." +#define STRING_CMD_UDAS_SUMMARY "{1} UDA defined" +#define STRING_CMD_UDAS_SUMMARY2 "{1} UDAs defined" + #define STRING_CMD_DELETE_USAGE "Deletes the specified task" #define STRING_CMD_DELETE_CONFIRM "Permanently delete task {1} '{2}'?" #define STRING_CMD_DELETE_TASK "Deleting task {1} '{2}'."