Code Reorganization

- Added the ability for a command to specify it's own pirmary keyword.
This commit is contained in:
Paul Beckingham 2011-05-23 20:23:53 -04:00
parent f8b44b68d7
commit f53d509930
9 changed files with 128 additions and 1 deletions

View file

@ -8,7 +8,8 @@ set (commands_SRCS Command.cpp Command.h
CmdExec.cpp CmdExec.h
CmdHelp.cpp CmdHelp.h
CmdInstall.cpp CmdInstall.h
CmdLogo.cpp CmdLogo.h)
CmdLogo.cpp CmdLogo.h
CmdTip.cpp CmdTip.h)
add_library (commands STATIC ${commands_SRCS})

View file

@ -35,6 +35,7 @@ extern Context context;
CmdExec::CmdExec ()
: _external_command ("")
{
_keyword = "execute";
_usage = "task execute <external command>";
_description = "Executes external commands and scripts";
_read_only = false;

View file

@ -36,6 +36,7 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
CmdHelp::CmdHelp ()
{
_keyword = "help";
_usage = "task help";
_description = "Displays this usage help text";
_read_only = true;

View file

@ -34,6 +34,7 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
CmdInstall::CmdInstall ()
{
_keyword = "install";
_usage = "task install <extension> [<extension> ...]";
_description = "Installs extensions and external scripts";
_read_only = true;

View file

@ -34,6 +34,7 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
CmdLogo::CmdLogo ()
{
_keyword = "logo";
_usage = "task logo";
_description = "Displays the Taskwarrior logo";
_read_only = true;

66
src/commands/CmdTip.cpp Normal file
View file

@ -0,0 +1,66 @@
////////////////////////////////////////////////////////////////////////////////
// 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 <stdlib.h>
#include <CmdTip.h>
#include <Context.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
CmdTip::CmdTip ()
: _external_command ("")
{
_keyword = "tip";
_usage = "task tip";
_description = "Displays helpful usage tips";
_read_only = true;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
bool CmdTip::implements (const std::string& command_line)
{
_external_command = "";
if (context.args.size () > 1 &&
(context.args[0] == "tip" ||
context.args[0] == "ti"))
{
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdTip::execute (const std::string&, std::string&)
{
// TODO Read tips file, pick one, display it.
return 0;
}
////////////////////////////////////////////////////////////////////////////////

46
src/commands/CmdTip.h Normal file
View file

@ -0,0 +1,46 @@
////////////////////////////////////////////////////////////////////////////////
// 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_CMDTIP
#define INCLUDED_CMDTIP
#include <string>
#include <Command.h>
class CmdTip : public Command
{
public:
CmdTip ();
bool implements (const std::string&);
int execute (const std::string&, std::string&);
private:
std::string _external_command;
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -31,6 +31,7 @@
#include <CmdHelp.h>
#include <CmdInstall.h>
#include <CmdLogo.h>
#include <CmdTip.h>
#include <Context.h>
extern Context context;
@ -42,6 +43,7 @@ Command* Command::factory (const std::string& name)
if (name == "execute") command = new CmdExec ();
else if (name == "help") command = new CmdHelp ();
else if (name == "install") command = new CmdInstall ();
else if (name == "tip") command = new CmdTip ();
else if (name == "_logo") command = new CmdLogo ();
else
throw std::string ("Unrecognized command object '") + name + "'";
@ -97,6 +99,12 @@ Command::~Command ()
{
}
////////////////////////////////////////////////////////////////////////////////
std::string Command::keyword () const
{
return _keyword;
}
////////////////////////////////////////////////////////////////////////////////
std::string Command::usage () const
{

View file

@ -40,6 +40,7 @@ public:
static Command* factory (const std::string&);
std::string keyword () const;
std::string usage () const;
std::string description () const;
bool read_only () const;
@ -48,6 +49,7 @@ public:
virtual int execute (const std::string&, std::string&) = 0;
protected:
std::string _keyword;
std::string _usage;
std::string _description;
bool _read_only;