mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
UDAs
- The 'udas' command now accepts a filter, and reports UDA usage counts. - The 'udas' command also detects and lists orphaned UDAs and usage counts.
This commit is contained in:
parent
19cfd5453d
commit
1b329d34b3
3 changed files with 55 additions and 2 deletions
|
@ -10,7 +10,7 @@ Features
|
|||
+ 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.
|
||||
and a '_udas' for completion purposes. Also detects UDA orphans.
|
||||
+ 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.
|
||||
|
|
|
@ -71,6 +71,10 @@ int CmdUDAs::execute (std::string& output)
|
|||
}
|
||||
}
|
||||
|
||||
// Load/filter all data.
|
||||
std::vector <Task> filtered;
|
||||
filter (filtered);
|
||||
|
||||
if (udas.size ())
|
||||
{
|
||||
std::sort (udas.begin (), udas.end ());
|
||||
|
@ -82,7 +86,7 @@ int CmdUDAs::execute (std::string& output)
|
|||
view.add (Column::factory ("string", STRING_COLUMN_LABEL_TYPE));
|
||||
view.add (Column::factory ("string", STRING_COLUMN_LABEL_LABEL));
|
||||
view.add (Column::factory ("string", STRING_COLUMN_LABEL_VALUES));
|
||||
|
||||
view.add (Column::factory ("string", STRING_COLUMN_LABEL_UDACOUNT));
|
||||
|
||||
std::vector <std::string>::iterator uda;
|
||||
for (uda = udas.begin (); uda != udas.end (); ++uda)
|
||||
|
@ -93,11 +97,19 @@ int CmdUDAs::execute (std::string& output)
|
|||
if (label == "")
|
||||
label = *uda;
|
||||
|
||||
// Count UDA usage by UDA.
|
||||
int count = 0;
|
||||
std::vector <Task>::iterator i;
|
||||
for (i = filtered.begin (); i != filtered.end (); ++i)
|
||||
if (i->has (*uda))
|
||||
++count;
|
||||
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, *uda);
|
||||
view.set (row, 1, type);
|
||||
view.set (row, 2, label);
|
||||
view.set (row, 3, values);
|
||||
view.set (row, 4, count);
|
||||
}
|
||||
|
||||
out << optionalBlankLine ()
|
||||
|
@ -114,6 +126,43 @@ int CmdUDAs::execute (std::string& output)
|
|||
rc = 1;
|
||||
}
|
||||
|
||||
// Orphans are task attributes that are not represented in context.columns.
|
||||
std::map <std::string, int> orphans;
|
||||
std::vector <Task>::iterator i;
|
||||
for (i = filtered.begin (); i != filtered.end (); ++i)
|
||||
{
|
||||
std::map <std::string, std::string>::iterator att;
|
||||
for (att = i->begin (); att != i->end (); ++att)
|
||||
if (att->first.substr (0, 11) != "annotation_" &&
|
||||
context.columns.find (att->first) == context.columns.end ())
|
||||
orphans[att->first]++;
|
||||
}
|
||||
|
||||
if (orphans.size ())
|
||||
{
|
||||
// Display the orphans and their counts.
|
||||
ViewText orphanView;
|
||||
orphanView.width (context.getWidth ());
|
||||
orphanView.add (Column::factory ("string", STRING_COLUMN_LABEL_ORPHAN));
|
||||
orphanView.add (Column::factory ("string", STRING_COLUMN_LABEL_UDACOUNT));
|
||||
|
||||
std::map <std::string, int>::iterator o;
|
||||
for (o = orphans.begin (); o != orphans.end (); ++o)
|
||||
{
|
||||
int row = orphanView.addRow ();
|
||||
orphanView.set (row, 0, o->first);
|
||||
orphanView.set (row, 1, o->second);
|
||||
}
|
||||
|
||||
out << optionalBlankLine ()
|
||||
<< orphanView.render ()
|
||||
<< optionalBlankLine ()
|
||||
<< (udas.size () == 1
|
||||
? format (STRING_CMD_UDAS_ORPHAN, udas.size ())
|
||||
: format (STRING_CMD_UDAS_ORPHANS, udas.size ()))
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
output = out.str ();
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -187,6 +187,8 @@
|
|||
#define STRING_COLUMN_LABEL_TYPE "Type"
|
||||
#define STRING_COLUMN_LABEL_LABEL "Label"
|
||||
#define STRING_COLUMN_LABEL_VALUES "Allowed Values"
|
||||
#define STRING_COLUMN_LABEL_UDACOUNT "Usage Count"
|
||||
#define STRING_COLUMN_LABEL_ORPHAN "Orphan UDA"
|
||||
|
||||
// Column Examples
|
||||
#define STRING_COLUMN_EXAMPLES_TAGS "home @chore"
|
||||
|
@ -315,6 +317,8 @@
|
|||
#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_UDAS_ORPHAN "{1} Orphan UDA"
|
||||
#define STRING_CMD_UDAS_ORPHANS "{1} Orphan UDAs"
|
||||
|
||||
#define STRING_CMD_DELETE_USAGE "Deletes the specified task"
|
||||
#define STRING_CMD_DELETE_CONFIRM "Permanently delete task {1} '{2}'?"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue