mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Commands
- 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:
parent
52599dca63
commit
afc97d566c
11 changed files with 63 additions and 49 deletions
|
@ -32,6 +32,7 @@
|
|||
'blanklines'.
|
||||
+ The 'verbose' configuration variable now accepts a specific list of items to
|
||||
be verbose about. See taskrc(5).
|
||||
+ New 'exec' command that runs external programs.
|
||||
|
||||
# Tracked Features, sorted by ID.
|
||||
+ Added feature #330, which supports the 'inverse' color attribute.
|
||||
|
|
1
NEWS
1
NEWS
|
@ -16,6 +16,7 @@ New Features in taskwarrior 2.0.0
|
|||
- Performance enhancements.
|
||||
- New 'next' report, that gauges urgency and reports the most urgent tasks.
|
||||
- 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
|
||||
list here.
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <CmdExec.h>
|
||||
#include <Context.h>
|
||||
|
||||
|
@ -33,26 +33,39 @@ extern Context context;
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdExec::execute (const std::string& commandLine, std::string& output)
|
||||
int CmdExec::execute (const std::string&, std::string&)
|
||||
{
|
||||
std::cout << "# CmdExec::execute\n";
|
||||
return 1;
|
||||
system (_external_command.c_str ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -34,12 +34,12 @@ class CmdExec : public Command
|
|||
{
|
||||
public:
|
||||
CmdExec ();
|
||||
~CmdExec ();
|
||||
|
||||
bool implements (const std::string&) const;
|
||||
bool implements (const std::string&);
|
||||
int execute (const std::string&, std::string&);
|
||||
|
||||
private:
|
||||
std::string _external_command;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <iostream>
|
||||
#include <iostream> // TODO Remove.
|
||||
#include <CmdInstall.h>
|
||||
#include <Context.h>
|
||||
|
||||
|
@ -34,17 +34,14 @@ extern Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CmdInstall::CmdInstall ()
|
||||
{
|
||||
_read_only = true;
|
||||
_displays_id = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CmdInstall::~CmdInstall ()
|
||||
bool CmdInstall::implements (const std::string& command_line)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CmdInstall::implements (const std::string& command_line) const
|
||||
{
|
||||
std::cout << "# CmdInstall::implements\n";
|
||||
std::cout << "# CmdInstall::implements '" << command_line << "'\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,9 +34,8 @@ class CmdInstall : public Command
|
|||
{
|
||||
public:
|
||||
CmdInstall ();
|
||||
~CmdInstall ();
|
||||
|
||||
bool implements (const std::string&) const;
|
||||
bool implements (const std::string&);
|
||||
int execute (const std::string&, std::string&);
|
||||
|
||||
private:
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <iostream>
|
||||
#include <iostream> // TODO Remove.
|
||||
#include <CmdLogo.h>
|
||||
#include <Context.h>
|
||||
#include <text.h>
|
||||
|
@ -35,21 +35,12 @@ extern Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CmdLogo::CmdLogo ()
|
||||
{
|
||||
_read_only = true;
|
||||
_displays_id = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CmdLogo::~CmdLogo ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CmdLogo::read_only () const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CmdLogo::implements (const std::string& command_line) const
|
||||
bool CmdLogo::implements (const std::string& command_line)
|
||||
{
|
||||
// TODO Upgrade to a parsed value.
|
||||
if (command_line.find ("_logo") != std::string::npos)
|
||||
|
|
|
@ -34,10 +34,8 @@ class CmdLogo : public Command
|
|||
{
|
||||
public:
|
||||
CmdLogo ();
|
||||
~CmdLogo ();
|
||||
|
||||
bool read_only () const;
|
||||
bool implements (const std::string&) const;
|
||||
bool implements (const std::string&);
|
||||
int execute (const std::string&, std::string&);
|
||||
|
||||
private:
|
||||
|
|
|
@ -51,13 +51,16 @@ Command* Command::factory (const std::string& name)
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Command::Command ()
|
||||
: _read_only (true)
|
||||
, _displays_id (true)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
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)
|
||||
{
|
||||
// _all = other._all;
|
||||
_read_only = other._read_only;
|
||||
_displays_id = other._displays_id;
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
@ -74,8 +78,8 @@ Command& Command::operator= (const Command& other)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Command::operator== (const Command& other) const
|
||||
{
|
||||
// return _all == other._all;
|
||||
return false;
|
||||
return _read_only == other._read_only &&
|
||||
_displays_id == other._displays_id;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -86,8 +90,13 @@ Command::~Command ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Command::read_only () const
|
||||
{
|
||||
std::cout << "# Command::read_only\n";
|
||||
return false;
|
||||
return _read_only;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Command::displays_id () const
|
||||
{
|
||||
return _displays_id;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -40,9 +40,14 @@ public:
|
|||
|
||||
static Command* factory (const std::string&);
|
||||
|
||||
virtual bool read_only () const;
|
||||
virtual bool implements (const std::string&) const = 0;
|
||||
bool read_only () const;
|
||||
bool displays_id () const;
|
||||
virtual bool implements (const std::string&) = 0;
|
||||
virtual int execute (const std::string&, std::string&) = 0;
|
||||
|
||||
protected:
|
||||
bool _read_only;
|
||||
bool _displays_id;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -788,9 +788,9 @@ int handleReportSummary (std::string& outs)
|
|||
ViewText view;
|
||||
view.width (context.getWidth ());
|
||||
view.add (Column::factory ("string", "Project"));
|
||||
view.add (Column::factory ("string", "Remaining"));
|
||||
view.add (Column::factory ("string", "Avg age"));
|
||||
view.add (Column::factory ("string", "Complete"));
|
||||
view.add (Column::factory ("string.right", "Remaining"));
|
||||
view.add (Column::factory ("string.right", "Avg age"));
|
||||
view.add (Column::factory ("string.right", "Complete"));
|
||||
view.add (Column::factory ("string", "0% 100%"));
|
||||
|
||||
Color bar_color (context.config.get ("color.summary.bar"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue