diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index a4dcdb724..5d134c030 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -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}) diff --git a/src/commands/CmdExec.cpp b/src/commands/CmdExec.cpp index 3cc03856a..12954e6d2 100644 --- a/src/commands/CmdExec.cpp +++ b/src/commands/CmdExec.cpp @@ -35,6 +35,7 @@ extern Context context; CmdExec::CmdExec () : _external_command ("") { + _keyword = "execute"; _usage = "task execute "; _description = "Executes external commands and scripts"; _read_only = false; diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 70b0ae488..15cfb834a 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -36,6 +36,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// CmdHelp::CmdHelp () { + _keyword = "help"; _usage = "task help"; _description = "Displays this usage help text"; _read_only = true; diff --git a/src/commands/CmdInstall.cpp b/src/commands/CmdInstall.cpp index 03b5f308d..57660469a 100644 --- a/src/commands/CmdInstall.cpp +++ b/src/commands/CmdInstall.cpp @@ -34,6 +34,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// CmdInstall::CmdInstall () { + _keyword = "install"; _usage = "task install [ ...]"; _description = "Installs extensions and external scripts"; _read_only = true; diff --git a/src/commands/CmdLogo.cpp b/src/commands/CmdLogo.cpp index 2191f47a6..3615f8a90 100644 --- a/src/commands/CmdLogo.cpp +++ b/src/commands/CmdLogo.cpp @@ -34,6 +34,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// CmdLogo::CmdLogo () { + _keyword = "logo"; _usage = "task logo"; _description = "Displays the Taskwarrior logo"; _read_only = true; diff --git a/src/commands/CmdTip.cpp b/src/commands/CmdTip.cpp new file mode 100644 index 000000000..c755ce539 --- /dev/null +++ b/src/commands/CmdTip.cpp @@ -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 +#include +#include + +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; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdTip.h b/src/commands/CmdTip.h new file mode 100644 index 000000000..e6c731d8b --- /dev/null +++ b/src/commands/CmdTip.h @@ -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 +#include + +class CmdTip : public Command +{ +public: + CmdTip (); + + bool implements (const std::string&); + int execute (const std::string&, std::string&); + +private: + std::string _external_command; +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 1e775a9bb..bbb188f4f 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include 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 { diff --git a/src/commands/Command.h b/src/commands/Command.h index ee08d9ef3..7c74d0be5 100644 --- a/src/commands/Command.h +++ b/src/commands/Command.h @@ -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;