- New 'exec' command that runs external programs, implemented by
  CmdExec.
- Restructured code so that only Commands implements ::read_only
  and ::displays_id methods, while derived objects simply set flags.
- Corrected column alignment in summary report.
This commit is contained in:
Paul Beckingham 2011-05-15 00:18:24 -04:00
parent 52599dca63
commit afc97d566c
11 changed files with 63 additions and 49 deletions

View file

@ -32,6 +32,7 @@
'blanklines'. 'blanklines'.
+ The 'verbose' configuration variable now accepts a specific list of items to + The 'verbose' configuration variable now accepts a specific list of items to
be verbose about. See taskrc(5). be verbose about. See taskrc(5).
+ New 'exec' command that runs external programs.
# Tracked Features, sorted by ID. # Tracked Features, sorted by ID.
+ Added feature #330, which supports the 'inverse' color attribute. + Added feature #330, which supports the 'inverse' color attribute.

1
NEWS
View file

@ -16,6 +16,7 @@ New Features in taskwarrior 2.0.0
- Performance enhancements. - Performance enhancements.
- New 'next' report, that gauges urgency and reports the most urgent tasks. - New 'next' report, that gauges urgency and reports the most urgent tasks.
- Fine control of verbosity through the 'verbose=' configuration variable. - Fine control of verbosity through the 'verbose=' configuration variable.
- New 'exec' command that runs external scripts/programs.
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

@ -25,7 +25,7 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <stdlib.h>
#include <CmdExec.h> #include <CmdExec.h>
#include <Context.h> #include <Context.h>
@ -33,26 +33,39 @@ extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdExec::CmdExec () CmdExec::CmdExec ()
: _external_command ("")
{ {
_read_only = false;
_displays_id = true;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdExec::~CmdExec () bool CmdExec::implements (const std::string& command_line)
{ {
} if (context.args.size () > 1 &&
(context.args[0] == "exec" ||
context.args[0] == "exe" ||
context.args[0] == "ex"))
{
for (int i = 1; i < context.args.size (); ++i)
{
if (i > 1)
_external_command += " ";
_external_command += context.args[i];
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool CmdExec::implements (const std::string& command_line) const
{
std::cout << "# CmdExec::implements\n";
return false; return false;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdExec::execute (const std::string& commandLine, std::string& output) int CmdExec::execute (const std::string&, std::string&)
{ {
std::cout << "# CmdExec::execute\n"; system (_external_command.c_str ());
return 1; return 0;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -34,12 +34,12 @@ class CmdExec : public Command
{ {
public: public:
CmdExec (); CmdExec ();
~CmdExec ();
bool implements (const std::string&) const; bool implements (const std::string&);
int execute (const std::string&, std::string&); int execute (const std::string&, std::string&);
private: private:
std::string _external_command;
}; };
#endif #endif

View file

@ -25,7 +25,7 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream> // TODO Remove.
#include <CmdInstall.h> #include <CmdInstall.h>
#include <Context.h> #include <Context.h>
@ -34,17 +34,14 @@ extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdInstall::CmdInstall () CmdInstall::CmdInstall ()
{ {
_read_only = true;
_displays_id = false;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdInstall::~CmdInstall () bool CmdInstall::implements (const std::string& command_line)
{ {
} std::cout << "# CmdInstall::implements '" << command_line << "'\n";
////////////////////////////////////////////////////////////////////////////////
bool CmdInstall::implements (const std::string& command_line) const
{
std::cout << "# CmdInstall::implements\n";
return false; return false;
} }

View file

@ -34,9 +34,8 @@ class CmdInstall : public Command
{ {
public: public:
CmdInstall (); CmdInstall ();
~CmdInstall ();
bool implements (const std::string&) const; bool implements (const std::string&);
int execute (const std::string&, std::string&); int execute (const std::string&, std::string&);
private: private:

View file

@ -25,7 +25,7 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream> // TODO Remove.
#include <CmdLogo.h> #include <CmdLogo.h>
#include <Context.h> #include <Context.h>
#include <text.h> #include <text.h>
@ -35,21 +35,12 @@ extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdLogo::CmdLogo () CmdLogo::CmdLogo ()
{ {
_read_only = true;
_displays_id = false;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdLogo::~CmdLogo () bool CmdLogo::implements (const std::string& command_line)
{
}
////////////////////////////////////////////////////////////////////////////////
bool CmdLogo::read_only () const
{
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool CmdLogo::implements (const std::string& command_line) const
{ {
// TODO Upgrade to a parsed value. // TODO Upgrade to a parsed value.
if (command_line.find ("_logo") != std::string::npos) if (command_line.find ("_logo") != std::string::npos)

View file

@ -34,10 +34,8 @@ class CmdLogo : public Command
{ {
public: public:
CmdLogo (); CmdLogo ();
~CmdLogo ();
bool read_only () const; bool implements (const std::string&);
bool implements (const std::string&) const;
int execute (const std::string&, std::string&); int execute (const std::string&, std::string&);
private: private:

View file

@ -51,13 +51,16 @@ Command* Command::factory (const std::string& name)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Command::Command () Command::Command ()
: _read_only (true)
, _displays_id (true)
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Command::Command (const Command& other) Command::Command (const Command& other)
{ {
// _all = other._all; _read_only = other._read_only;
_displays_id = other._displays_id;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -65,7 +68,8 @@ Command& Command::operator= (const Command& other)
{ {
if (this != &other) if (this != &other)
{ {
// _all = other._all; _read_only = other._read_only;
_displays_id = other._displays_id;
} }
return *this; return *this;
@ -74,8 +78,8 @@ Command& Command::operator= (const Command& other)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Command::operator== (const Command& other) const bool Command::operator== (const Command& other) const
{ {
// return _all == other._all; return _read_only == other._read_only &&
return false; _displays_id == other._displays_id;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -86,8 +90,13 @@ Command::~Command ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Command::read_only () const bool Command::read_only () const
{ {
std::cout << "# Command::read_only\n"; return _read_only;
return false; }
////////////////////////////////////////////////////////////////////////////////
bool Command::displays_id () const
{
return _displays_id;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -40,9 +40,14 @@ public:
static Command* factory (const std::string&); static Command* factory (const std::string&);
virtual bool read_only () const; bool read_only () const;
virtual bool implements (const std::string&) const = 0; bool displays_id () const;
virtual bool implements (const std::string&) = 0;
virtual int execute (const std::string&, std::string&) = 0; virtual int execute (const std::string&, std::string&) = 0;
protected:
bool _read_only;
bool _displays_id;
}; };
#endif #endif

View file

@ -788,9 +788,9 @@ int handleReportSummary (std::string& outs)
ViewText view; ViewText view;
view.width (context.getWidth ()); view.width (context.getWidth ());
view.add (Column::factory ("string", "Project")); view.add (Column::factory ("string", "Project"));
view.add (Column::factory ("string", "Remaining")); view.add (Column::factory ("string.right", "Remaining"));
view.add (Column::factory ("string", "Avg age")); view.add (Column::factory ("string.right", "Avg age"));
view.add (Column::factory ("string", "Complete")); view.add (Column::factory ("string.right", "Complete"));
view.add (Column::factory ("string", "0% 100%")); view.add (Column::factory ("string", "0% 100%"));
Color bar_color (context.config.get ("color.summary.bar")); Color bar_color (context.config.get ("color.summary.bar"));