mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Feature #921
- Feature #921, which implements a 'udas' command that describes defined UDAs, and a '_udas' for completion purposes.
This commit is contained in:
parent
ca1fce280b
commit
b63bd9e985
8 changed files with 232 additions and 0 deletions
|
@ -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)
|
||||
|
|
157
src/commands/CmdUDAs.cpp
Normal file
157
src/commands/CmdUDAs.cpp
Normal file
|
@ -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 <sstream>
|
||||
#include <algorithm>
|
||||
#include <Context.h>
|
||||
#include <ViewText.h>
|
||||
#include <main.h>
|
||||
#include <text.h>
|
||||
#include <util.h>
|
||||
#include <i18n.h>
|
||||
#include <CmdUDAs.h>
|
||||
|
||||
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 <std::string> names;
|
||||
context.config.all (names);
|
||||
|
||||
std::vector <std::string> udas;
|
||||
std::vector <std::string>::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 <std::string>::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 <std::string> names;
|
||||
context.config.all (names);
|
||||
|
||||
std::vector <std::string> udas;
|
||||
std::vector <std::string>::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;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
50
src/commands/CmdUDAs.h
Normal file
50
src/commands/CmdUDAs.h
Normal file
|
@ -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 <string>
|
||||
#include <Command.h>
|
||||
|
||||
class CmdUDAs : public Command
|
||||
{
|
||||
public:
|
||||
CmdUDAs ();
|
||||
int execute (std::string&);
|
||||
};
|
||||
|
||||
class CmdCompletionUDAs : public Command
|
||||
{
|
||||
public:
|
||||
CmdCompletionUDAs ();
|
||||
int execute (std::string&);
|
||||
};
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -85,6 +85,7 @@
|
|||
//#include <CmdSynch.h>
|
||||
#include <CmdTags.h>
|
||||
#include <CmdTimesheet.h>
|
||||
#include <CmdUDAs.h>
|
||||
#include <CmdUndo.h>
|
||||
#include <CmdUrgency.h>
|
||||
#include <CmdVersion.h>
|
||||
|
@ -114,6 +115,7 @@ void Command::factory (std::map <std::string, Command*>& 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 <std::string, Command*>& 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;
|
||||
|
|
|
@ -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}'."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue