- New command that lists reports and their descriptions.
This commit is contained in:
Paul Beckingham 2011-05-30 12:23:23 -04:00
parent 37b48c56d5
commit 73e9f52793
7 changed files with 166 additions and 0 deletions

View file

@ -51,6 +51,8 @@
+ Added feature #740, that allows for indented annotations, controlled by the + Added feature #740, that allows for indented annotations, controlled by the
'indent.annotation' configuration variable (thanks to Steve Rader, Tomas 'indent.annotation' configuration variable (thanks to Steve Rader, Tomas
Cech). Cech).
+ Added feature #755, adding a new command 'reports' that lists reports and
their descriptions.
# Tracked Bugs, sorted by ID. # Tracked Bugs, sorted by ID.
+ Fixed bug #511, which caused display problem on Cygwin when colored output + Fixed bug #511, which caused display problem on Cygwin when colored output

1
NEWS
View file

@ -18,6 +18,7 @@ New Features in taskwarrior 2.0.0
- Fine control of verbosity through the 'verbose=' configuration variable. - Fine control of verbosity through the 'verbose=' configuration variable.
- New 'execute' command that runs external scripts/programs. - New 'execute' command that runs external scripts/programs.
- JSON is the new default export format. - JSON is the new default export format.
- New 'reports' command that lists reports and their descriptions.
Please refer to the ChangeLog file for full details. There are too many to Please refer to the ChangeLog file for full details. There are too many to
list here. list here.

View file

@ -224,6 +224,8 @@ int Context::dispatch2 (std::string &out)
if (args.extract_command (keywords, command)) if (args.extract_command (keywords, command))
{ {
Command* c = commands[command]; Command* c = commands[command];
// GC is invoked prior to running any command that displays task IDs.
if (c->displays_id ()) if (c->displays_id ())
tdb.gc (); tdb.gc ();

View file

@ -28,6 +28,7 @@ set (commands_SRCS Command.cpp Command.h
CmdLogo.cpp CmdLogo.h CmdLogo.cpp CmdLogo.h
CmdPrepend.cpp CmdPrepend.h CmdPrepend.cpp CmdPrepend.h
CmdProjects.cpp CmdProjects.h CmdProjects.cpp CmdProjects.h
CmdReports.cpp CmdReports.h
CmdShell.cpp CmdShell.h CmdShell.cpp CmdShell.h
CmdShow.cpp CmdShow.h CmdShow.cpp CmdShow.h
CmdStart.cpp CmdStart.h CmdStart.cpp CmdStart.h

116
src/commands/CmdReports.cpp Normal file
View file

@ -0,0 +1,116 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <sstream>
#include <Context.h>
#include <ViewText.h>
#include <text.h>
#include <CmdReports.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
CmdReports::CmdReports ()
{
_keyword = "reports";
_usage = "task reports";
_description = "Lists all supported reports.";
_read_only = true;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdReports::execute (const std::string&, std::string& output)
{
std::vector <std::string> reports;
// Add custom reports.
std::vector <std::string> vars;
context.config.all (vars);
std::vector <std::string>::iterator i;
for (i = vars.begin (); i != vars.end (); ++i)
{
if (i->substr (0, 7) == "report.")
{
std::string report = i->substr (7);
std::string::size_type columns = report.find (".columns");
if (columns != std::string::npos)
reports.push_back (report.substr (0, columns));
}
}
// Add known reports.
reports.push_back ("burndown.daily");
reports.push_back ("burndown.monthly");
reports.push_back ("burndown.weekly");
reports.push_back ("ghistory.annual");
reports.push_back ("ghistory.monthly");
reports.push_back ("history.annual");
reports.push_back ("history.monthly");
reports.push_back ("information");
reports.push_back ("projects");
reports.push_back ("summary");
reports.push_back ("tags");
std::sort (reports.begin (), reports.end ());
// Compose the output.
std::stringstream out;
ViewText view;
view.width (context.getWidth ());
view.add (Column::factory ("string", "Report"));
view.add (Column::factory ("string", "Description"));
// If an alternating row color is specified, notify the table.
if (context.color ())
{
Color alternate (context.config.get ("color.alternate"));
view.colorOdd (alternate);
view.intraColorOdd (alternate);
}
std::vector <std::string>::iterator report;
for (report = reports.begin (); report != reports.end (); ++report)
{
int row = view.addRow ();
view.set (row, 0, *report);
view.set (row, 1, context.commands[*report]->description ());
}
out << optionalBlankLine ()
<< view.render ()
<< optionalBlankLine ()
<< reports.size ()
<< " reports"
<< "\n";
output = out.str ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////

42
src/commands/CmdReports.h Normal file
View file

@ -0,0 +1,42 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_CMDREPORTS
#define INCLUDED_CMDREPORTS
#define L10N // Localization complete.
#include <string>
#include <Command.h>
class CmdReports : public Command
{
public:
CmdReports ();
int execute (const std::string&, std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -50,6 +50,7 @@
#include <CmdLogo.h> #include <CmdLogo.h>
#include <CmdPrepend.h> #include <CmdPrepend.h>
#include <CmdProjects.h> #include <CmdProjects.h>
#include <CmdReports.h>
#include <CmdShell.h> #include <CmdShell.h>
#include <CmdShow.h> #include <CmdShow.h>
#include <CmdStart.h> #include <CmdStart.h>
@ -99,6 +100,7 @@ void Command::factory (std::map <std::string, Command*>& all)
c = new CmdLogo (); all[c->keyword ()] = c; c = new CmdLogo (); all[c->keyword ()] = c;
c = new CmdPrepend (); all[c->keyword ()] = c; c = new CmdPrepend (); all[c->keyword ()] = c;
c = new CmdProjects (); all[c->keyword ()] = c; c = new CmdProjects (); all[c->keyword ()] = c;
c = new CmdReports (); all[c->keyword ()] = c;
c = new CmdShell (); all[c->keyword ()] = c; c = new CmdShell (); all[c->keyword ()] = c;
c = new CmdShow (); all[c->keyword ()] = c; c = new CmdShow (); all[c->keyword ()] = c;
c = new CmdStart (); all[c->keyword ()] = c; c = new CmdStart (); all[c->keyword ()] = c;