From fc77e04b54f5c7e8af2bc0ca3070f7d09357ae88 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 24 May 2011 20:43:50 -0400 Subject: [PATCH] Commands - Migrated handleVersion to CmdVersion. --- src/CMakeLists.txt | 3 +- src/Cmd.cpp | 2 - src/Context.cpp | 1 - src/command.cpp | 73 ---------------------- src/commands/CMakeLists.txt | 18 +++--- src/commands/CmdVersion.cpp | 119 ++++++++++++++++++++++++++++++++++++ src/commands/CmdVersion.h | 41 +++++++++++++ src/commands/Command.cpp | 2 + src/main.h | 1 - 9 files changed, 174 insertions(+), 86 deletions(-) create mode 100644 src/commands/CmdVersion.cpp create mode 100644 src/commands/CmdVersion.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e0195aae9..704fbffd8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required (VERSION 2.8) -include_directories (${CMAKE_SOURCE_DIR}/src +include_directories (${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/commands ${CMAKE_SOURCE_DIR}/src/columns ${TASK_INCLUDE_DIRS}) diff --git a/src/Cmd.cpp b/src/Cmd.cpp index c1b1aaef1..93e09061c 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -177,7 +177,6 @@ void Cmd::load () commands.push_back ("summary"); commands.push_back ("timesheet"); commands.push_back ("undo"); - commands.push_back ("version"); commands.push_back ("merge"); commands.push_back ("push"); commands.push_back ("pull"); @@ -272,7 +271,6 @@ bool Cmd::isReadOnlyCommand () command == "stats" || command == "summary" || command == "timesheet" || - command == "version" || validCustom (command)) return true; diff --git a/src/Context.cpp b/src/Context.cpp index 1383d6eac..dcf5ad245 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -250,7 +250,6 @@ int Context::dispatch (std::string &out) // TODO Chain-of-command pattern dispatch. if (cmd.command == "projects") { rc = handleProjects (out); } else if (cmd.command == "colors") { rc = handleColor (out); } - else if (cmd.command == "version") { rc = handleVersion (out); } else if (cmd.command == "config") { rc = handleConfig (out); } else if (cmd.command == "show") { rc = handleShow (out); } else if (cmd.command == "stats") { rc = handleReportStats (out); } diff --git a/src/command.cpp b/src/command.cpp index b015fd0da..a1ccb5ebb 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -903,79 +903,6 @@ void handlePull (std::string& outs) "'pull.default.uri' entry in your .taskrc file."); } -//////////////////////////////////////////////////////////////////////////////// -int handleVersion (std::string& outs) -{ - int rc = 0; - std::stringstream out; - - // Create a table for the disclaimer. - int width = context.getWidth (); - ViewText disclaimer; - disclaimer.width (width); - disclaimer.add (Column::factory ("string", "")); - disclaimer.set (disclaimer.addRow (), 0, - "Taskwarrior may be copied only under the terms of the GNU General Public " - "License, which may be found in the taskwarrior source kit."); - - // Create a table for the URL. - ViewText link; - link.width (width); - link.add (Column::factory ("string", "")); - link.set (link.addRow (), 0, - "Documentation for taskwarrior can be found using 'man task', 'man taskrc', " - "'man task-tutorial', 'man task-color', 'man task-sync', 'man task-faq' or at " - "http://taskwarrior.org"); - - Color bold ("bold"); - - out << "\n" - << (context.color () ? bold.colorize (PACKAGE) : PACKAGE) - << " " - << (context.color () ? bold.colorize (VERSION) : VERSION) - << " built for " - -#if defined (DARWIN) - << "darwin" -#elif defined (SOLARIS) - << "solaris" -#elif defined (CYGWIN) - << "cygwin" -#elif defined (OPENBSD) - << "openbsd" -#elif defined (HAIKU) - << "haiku" -#elif defined (FREEBSD) - << "freebsd" -#elif defined (LINUX) - << "linux" -#else - << "unknown" -#endif - -#ifdef HAVE_LIBREADLINE - << "-readline" -#endif - -#ifdef HAVE_LIBLUA - << "-lua" -#endif - - << "\n" - << "Copyright (C) 2006 - 2011 P. Beckingham, F. Hernandez.\n" -#ifdef HAVE_LIBLUA - << "Portions of this software Copyright (C) 1994 – 2008 Lua.org, PUC-Rio.\n" -#endif - << "\n" - << disclaimer.render () - << "\n" - << link.render () - << "\n"; - - outs = out.str (); - return rc; -} - //////////////////////////////////////////////////////////////////////////////// int handleShow (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 8cd06d4ee..b7f983ddc 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -1,17 +1,19 @@ cmake_minimum_required (VERSION 2.8) -include_directories (${CMAKE_SOURCE_DIR}/src +include_directories (${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/commands ${CMAKE_SOURCE_DIR}/src/columns ${TASK_INCLUDE_DIRS}) -set (commands_SRCS Command.cpp Command.h - CmdCustom.cpp CmdCustom.h - CmdExec.cpp CmdExec.h - CmdHelp.cpp CmdHelp.h +set (commands_SRCS Command.cpp Command.h + CmdCustom.cpp CmdCustom.h + CmdExec.cpp CmdExec.h + CmdHelp.cpp CmdHelp.h CmdInstall.cpp CmdInstall.h - CmdLogo.cpp CmdLogo.h - CmdTags.cpp CmdTags.h - CmdTip.cpp CmdTip.h) + CmdLogo.cpp CmdLogo.h + CmdTags.cpp CmdTags.h + CmdTip.cpp CmdTip.h + CmdVersion.cpp CmdVersion.h) add_library (commands STATIC ${commands_SRCS}) diff --git a/src/commands/CmdVersion.cpp b/src/commands/CmdVersion.cpp new file mode 100644 index 000000000..fa38ff5ba --- /dev/null +++ b/src/commands/CmdVersion.cpp @@ -0,0 +1,119 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdVersion::CmdVersion () +{ + _keyword = "version"; + _usage = "task version"; + _description = "Shows the taskwarrior version number."; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdVersion::execute (const std::string& command_line, std::string& output) +{ + std::stringstream out; + + // Create a table for the disclaimer. + int width = context.getWidth (); + ViewText disclaimer; + disclaimer.width (width); + disclaimer.add (Column::factory ("string", "")); + disclaimer.set (disclaimer.addRow (), 0, + "Taskwarrior may be copied only under the terms of the GNU General Public " + "License, which may be found in the taskwarrior source kit."); + + // Create a table for the URL. + ViewText link; + link.width (width); + link.add (Column::factory ("string", "")); + link.set (link.addRow (), 0, + "Documentation for taskwarrior can be found using 'man task', 'man taskrc', " + "'man task-tutorial', 'man task-color', 'man task-sync', 'man task-faq' or at " + "http://taskwarrior.org"); + + Color bold ("bold"); + + out << "\n" + << (context.color () ? bold.colorize (PACKAGE) : PACKAGE) + << " " + << (context.color () ? bold.colorize (VERSION) : VERSION) + << " built for " + +#if defined (DARWIN) + << "darwin" +#elif defined (SOLARIS) + << "solaris" +#elif defined (CYGWIN) + << "cygwin" +#elif defined (OPENBSD) + << "openbsd" +#elif defined (HAIKU) + << "haiku" +#elif defined (FREEBSD) + << "freebsd" +#elif defined (LINUX) + << "linux" +#else + << "unknown" +#endif + +#ifdef HAVE_LIBREADLINE + << "-readline" +#endif + +#ifdef HAVE_LIBLUA + << "-lua" +#endif + + << "\n" + << "Copyright (C) 2006 - 2011 P. Beckingham, F. Hernandez.\n" +#ifdef HAVE_LIBLUA + << "Portions of this software Copyright (C) 1994 – 2008 Lua.org, PUC-Rio.\n" +#endif + << "\n" + << disclaimer.render () + << "\n" + << link.render () + << "\n"; + + output = out.str (); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdVersion.h b/src/commands/CmdVersion.h new file mode 100644 index 000000000..c4b463844 --- /dev/null +++ b/src/commands/CmdVersion.h @@ -0,0 +1,41 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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_CMDVERSION +#define INCLUDED_CMDVERSION + +#include +#include + +class CmdVersion : public Command +{ +public: + CmdVersion (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index ee5be5b18..58659c608 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include extern Context context; @@ -50,6 +51,7 @@ void Command::factory (std::map & all) c = new CmdLogo (); all[c->keyword ()] = c; c = new CmdTags (); all[c->keyword ()] = c; c = new CmdTip (); all[c->keyword ()] = c; + c = new CmdVersion (); all[c->keyword ()] = c; // Instantiate a command object for each custom report. std::vector variables; diff --git a/src/main.h b/src/main.h index 15b00157f..a79b8236a 100644 --- a/src/main.h +++ b/src/main.h @@ -66,7 +66,6 @@ int handleUrgency (std::string&); int handleQuery (std::string&); int handleZshCompletionCommands (std::string&); int handleZshCompletionIDs (std::string&); -int handleVersion (std::string&); int handleConfig (std::string&); int handleShow (std::string&); int handleDelete (std::string&);