diff --git a/ChangeLog b/ChangeLog index 8fcf94f05..8869fa665 100644 --- a/ChangeLog +++ b/ChangeLog @@ -51,6 +51,8 @@ + Added feature #740, that allows for indented annotations, controlled by the 'indent.annotation' configuration variable (thanks to Steve Rader, Tomas Cech). + + Added feature #755, adding a new command 'reports' that lists reports and + their descriptions. # Tracked Bugs, sorted by ID. + Fixed bug #511, which caused display problem on Cygwin when colored output diff --git a/NEWS b/NEWS index 918bcd13c..94733d47d 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ New Features in taskwarrior 2.0.0 - Fine control of verbosity through the 'verbose=' configuration variable. - New 'execute' command that runs external scripts/programs. - 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 list here. diff --git a/src/Context.cpp b/src/Context.cpp index 2d90c45b8..3bf9269d5 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -224,6 +224,8 @@ int Context::dispatch2 (std::string &out) if (args.extract_command (keywords, command)) { Command* c = commands[command]; + + // GC is invoked prior to running any command that displays task IDs. if (c->displays_id ()) tdb.gc (); diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index e9c8d21de..b25cd516f 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -28,6 +28,7 @@ set (commands_SRCS Command.cpp Command.h CmdLogo.cpp CmdLogo.h CmdPrepend.cpp CmdPrepend.h CmdProjects.cpp CmdProjects.h + CmdReports.cpp CmdReports.h CmdShell.cpp CmdShell.h CmdShow.cpp CmdShow.h CmdStart.cpp CmdStart.h diff --git a/src/commands/CmdReports.cpp b/src/commands/CmdReports.cpp new file mode 100644 index 000000000..f6a70d2e0 --- /dev/null +++ b/src/commands/CmdReports.cpp @@ -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 +#include +#include +#include +#include + +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 reports; + + // Add custom reports. + std::vector vars; + context.config.all (vars); + + std::vector ::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 ::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; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdReports.h b/src/commands/CmdReports.h new file mode 100644 index 000000000..bb9bb72a2 --- /dev/null +++ b/src/commands/CmdReports.h @@ -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 +#include + +class CmdReports : public Command +{ +public: + CmdReports (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index d525d6757..7dd396a39 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -99,6 +100,7 @@ void Command::factory (std::map & all) c = new CmdLogo (); all[c->keyword ()] = c; c = new CmdPrepend (); 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 CmdShow (); all[c->keyword ()] = c; c = new CmdStart (); all[c->keyword ()] = c;