From ed97fcc108a1261202adf1f2dd059d90d7702155 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 28 May 2011 13:15:19 -0400 Subject: [PATCH] Commands - diag - Migrated diag.cpp to CmdDiagnostics. --- src/CMakeLists.txt | 1 - src/Cmd.cpp | 2 - src/Context.cpp | 1 - src/commands/CMakeLists.txt | 23 +- src/{diag.cpp => commands/CmdDiagnostics.cpp} | 235 ++++++++++-------- src/commands/CmdDiagnostics.h | 42 ++++ src/commands/CmdHelp.cpp | 4 - src/commands/Command.cpp | 6 +- src/main.h | 3 - 9 files changed, 184 insertions(+), 133 deletions(-) rename src/{diag.cpp => commands/CmdDiagnostics.cpp} (52%) create mode 100644 src/commands/CmdDiagnostics.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1cc8f64e2..94bcea4b9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,7 +43,6 @@ set (task_SRCS API.cpp API.h burndown.cpp command.cpp dependency.cpp - diag.cpp edit.cpp export.cpp feedback.cpp diff --git a/src/Cmd.cpp b/src/Cmd.cpp index e897259df..f17ed04d8 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -158,7 +158,6 @@ void Cmd::load () commands.push_back ("colors"); commands.push_back ("config"); commands.push_back ("delete"); - commands.push_back ("diagnostics"); commands.push_back ("done"); commands.push_back ("duplicate"); commands.push_back ("edit"); @@ -256,7 +255,6 @@ bool Cmd::isReadOnlyCommand () command == "ids" || command == "calendar" || command == "colors" || - command == "diagnostics" || command == "config" || command == "help" || command == "projects" || diff --git a/src/Context.cpp b/src/Context.cpp index ec0b53042..649786392 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -283,7 +283,6 @@ int Context::dispatch (std::string &out) handleMerge (out); } else if (cmd.command == "push") { handlePush (out); } else if (cmd.command == "pull") { handlePull (out); } - else if (cmd.command == "diagnostics") { handleDiagnostics (out); } else if (cmd.command == "count") { rc = handleCount (out); } else if (cmd.command == "ids") { rc = handleIds (out); } else if (cmd.command == "_projects") { rc = handleCompletionProjects (out); } diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 9e2d5550e..ed013037c 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -5,17 +5,18 @@ include_directories (${CMAKE_SOURCE_DIR} ${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 - CmdInfo.cpp CmdInfo.h - CmdInstall.cpp CmdInstall.h - CmdLogo.cpp CmdLogo.h - CmdShow.cpp CmdShow.h - CmdTags.cpp CmdTags.h - CmdTip.cpp CmdTip.h - CmdVersion.cpp CmdVersion.h) +set (commands_SRCS Command.cpp Command.h + CmdCustom.cpp CmdCustom.h + CmdDiagnostics.cpp CmdDiagnostics.h + CmdExec.cpp CmdExec.h + CmdHelp.cpp CmdHelp.h + CmdInfo.cpp CmdInfo.h + CmdInstall.cpp CmdInstall.h + CmdLogo.cpp CmdLogo.h + CmdShow.cpp CmdShow.h + CmdTags.cpp CmdTags.h + CmdTip.cpp CmdTip.h + CmdVersion.cpp CmdVersion.h) add_library (commands STATIC ${commands_SRCS}) diff --git a/src/diag.cpp b/src/commands/CmdDiagnostics.cpp similarity index 52% rename from src/diag.cpp rename to src/commands/CmdDiagnostics.cpp index bf4c9fdb2..7d0c05883 100644 --- a/src/diag.cpp +++ b/src/commands/CmdDiagnostics.cpp @@ -25,18 +25,10 @@ // //////////////////////////////////////////////////////////////////////////////// -#include #include #include -#include -#include -#include -#include -#include - #include -#include -#include +#include #include #include #ifdef HAVE_COMMIT @@ -50,165 +42,188 @@ extern "C" } #endif +#include + extern Context context; +//////////////////////////////////////////////////////////////////////////////// +CmdDiagnostics::CmdDiagnostics () +{ + _keyword = "diagnostics"; + _usage = "task diagnostics"; + _description = "Shows information needed when reporting a problem."; + _read_only = true; + _displays_id = false; +} + //////////////////////////////////////////////////////////////////////////////// // This command will generate output that is intended to help diagnose problems. // // Although this will change over time, initially this command will answer the // kind of questions we always have to ask whenever something is wrong. -void handleDiagnostics (std::string& outs) +int CmdDiagnostics::execute (const std::string& command_line, std::string& output) { - std::cout << "\n" << PACKAGE_STRING << "\n"; + Color bold ("bold"); - std::cout << " Platform: " - << + std::stringstream out; + out << "\n" + << bold.colorize (PACKAGE_STRING) + << "\n"; + + out << " Platform: " + << #if defined (DARWIN) - "Darwin" + "Darwin" #elif defined (SOLARIS) - "Solaris" + "Solaris" #elif defined (CYGWIN) - "Cygwin" + "Cygwin" #elif defined (OPENBSD) - "OpenBSD" + "OpenBSD" #elif defined (HAIKU) - "Haiku" + "Haiku" #elif defined (FREEBSD) - "FreeBSD" + "FreeBSD" #elif defined (LINUX) - "Linux" + "Linux" #else - "" + "" #endif - << "\n\n"; + << "\n\n"; // Compiler. - std::cout << "Compiler\n" + out << bold.colorize ("Compiler") + << "\n" #ifdef __VERSION__ - << " Version: " << __VERSION__ << "\n" + << " Version: " << __VERSION__ << "\n" #endif - << " Caps:" + << " Caps:" #ifdef __STDC__ - << " +stdc" + << " +stdc" #endif #ifdef __STDC_HOSTED__ - << " +stdc_hosted" + << " +stdc_hosted" #endif #ifdef __STDC_VERSION__ - << " +" << __STDC_VERSION__ + << " +" << __STDC_VERSION__ #endif #ifdef _POSIX_VERSION - << " +" << _POSIX_VERSION + << " +" << _POSIX_VERSION #endif #ifdef _POSIX2_C_VERSION - << " +" << _POSIX2_C_VERSION + << " +" << _POSIX2_C_VERSION #endif #ifdef _ILP32 - << " +ILP32" + << " +ILP32" #endif #ifdef _LP64 - << " +LP64" + << " +LP64" #endif - << " +c" << sizeof (char) - << " +i" << sizeof (int) - << " +l" << sizeof (long) - << " +vp" << sizeof (void*) - << "\n\n"; + << " +c" << sizeof (char) + << " +i" << sizeof (int) + << " +l" << sizeof (long) + << " +vp" << sizeof (void*) + << "\n\n"; - std::cout << "Libraries\n"; + out << bold.colorize ("Libraries") + << "\n"; - std::cout << " Readline: " + out << " Readline: " #ifdef HAVE_LIBREADLINE - << std::setbase (16) << RL_READLINE_VERSION + << std::setbase (16) << RL_READLINE_VERSION #else - << "n/a" + << "n/a" #endif - << "\n"; + << "\n"; - std::cout << " Lua: " + out << " Lua: " #ifdef HAVE_LIBLUA - << LUA_RELEASE + << LUA_RELEASE #else - << "n/a" + << "n/a" #endif - << "\n\n"; + << "\n\n"; + + out << bold.colorize ("Build Features") + << "\n" - std::cout << "Build Features\n" // Build date. - << " Built: " << __DATE__ << " " << __TIME__ << "\n" + << " Built: " << __DATE__ << " " << __TIME__ << "\n" #ifdef HAVE_COMMIT - << " Commit: " << COMMIT << "\n" + << " Commit: " << COMMIT << "\n" #endif #ifdef HAVE_CMAKE - << " CMake: " << CMAKE_VERSION << "\n" + << " CMake: " << CMAKE_VERSION << "\n" #endif - << " Caps:" + << " Caps:" #ifdef HAVE_LIBPTHREAD - << " +pthreads" + << " +pthreads" #else - << " -pthreads" + << " -pthreads" #endif #ifdef HAVE_SRANDOM - << " +srandom" + << " +srandom" #else - << " -srandom" + << " -srandom" #endif #ifdef HAVE_RANDOM - << " +random" + << " +random" #else - << " -random" + << " -random" #endif #ifdef HAVE_UUID - << " +uuid" + << " +uuid" #else - << " -uuid" + << " -uuid" #endif - << "\n\n"; + << "\n\n"; // Config: .taskrc found, readable, writable - std::cout << "Configuration\n" - << " File: " << context.config.original_file.data - << (context.config.original_file.exists () ? " (found)" : " (missing)") - << ", " << context.config.original_file.size () << " bytes" - << ", mode " - << std::setbase (8) - << context.config.original_file.mode () - << "\n"; + out << bold.colorize ("Configuration") + << "\n" + << " File: " << context.config.original_file.data + << (context.config.original_file.exists () ? " (found)" : " (missing)") + << ", " << context.config.original_file.size () << " bytes" + << ", mode " + << std::setbase (8) + << context.config.original_file.mode () + << "\n"; // Config: data.location found, readable, writable File location (context.config.get ("data.location")); - std::cout << " Data: " << location.data - << (location.exists () ? " (found)" : " (missing)") - << ", " << (location.is_directory () ? "dir" : "?") - << ", mode " - << std::setbase (8) - << location.mode () - << "\n"; + out << " Data: " << location.data + << (location.exists () ? " (found)" : " (missing)") + << ", " << (location.is_directory () ? "dir" : "?") + << ", mode " + << std::setbase (8) + << location.mode () + << "\n"; - std::cout << " Locking: " - << (context.config.getBoolean ("locking") ? "Enabled" : "Disabled") - << "\n"; + out << " Locking: " + << (context.config.getBoolean ("locking") ? "Enabled" : "Disabled") + << "\n"; - std::cout << " Regex: " - << (context.config.getBoolean ("regex") ? "Enabled" : "Disabled") - << "\n"; + out << " Regex: " + << (context.config.getBoolean ("regex") ? "Enabled" : "Disabled") + << "\n"; // Determine rc.editor/$EDITOR/$VISUAL. char* peditor; if (context.config.get ("editor") != "") - std::cout << " rc.editor: " << context.config.get ("editor") << "\n"; + out << " rc.editor: " << context.config.get ("editor") << "\n"; else if ((peditor = getenv ("VISUAL")) != NULL) - std::cout << " $VISUAL: " << peditor << "\n"; + out << " $VISUAL: " << peditor << "\n"; else if ((peditor = getenv ("EDITOR")) != NULL) - std::cout << " $EDITOR: " << peditor << "\n"; + out << " $EDITOR: " << peditor << "\n"; - std::cout << "\n"; + out << "\n"; // External commands. - std::cout << "External Utilities\n"; + out << bold.colorize ("External Utilities") + << "\n"; { std::vector matches; char buffer [1024] = {0}; @@ -219,9 +234,9 @@ void handleDiagnostics (std::string& outs) pclose (fp); if (p) - std::cout << " scp: " - << (regexMatch (buffer, "usage") ? "found" : "n/a") - << "\n"; + out << " scp: " + << (regexMatch (buffer, "usage") ? "found" : "n/a") + << "\n"; } if ((fp = popen ("rsync --version 2>&1", "r"))) @@ -234,9 +249,9 @@ void handleDiagnostics (std::string& outs) { matches.clear (); regexMatch (matches, buffer, "version ([0-9]+\\.[0-9]+\\.[0-9]+)"); - std::cout << " rsync: " - << (matches.size () ? matches[0] : "n/a") - << "\n"; + out << " rsync: " + << (matches.size () ? matches[0] : "n/a") + << "\n"; } } @@ -250,19 +265,20 @@ void handleDiagnostics (std::string& outs) { matches.clear (); regexMatch (matches, buffer, "curl ([0-9]+\\.[0-9]+\\.[0-9]+)"); - std::cout << " curl: " - << (matches.size () ? matches[0] : "n/a") - << "\n"; + out << " curl: " + << (matches.size () ? matches[0] : "n/a") + << "\n"; } } - std::cout << "\n"; + out << "\n"; } // Generate 1000 UUIDs and verify they are all unique. - std::cout << "Tests\n"; + out << bold.colorize ("Tests") + << "\n"; { - std::cout << " UUID gen: "; + out << " UUID gen: "; std::vector uuids; std::string id; for (int i = 0; i < 1000; i++) @@ -270,7 +286,7 @@ void handleDiagnostics (std::string& outs) id = uuid (); if (std::find (uuids.begin (), uuids.end (), id) != uuids.end ()) { - std::cout << "Failed - duplicate UUID at iteration " << i << "\n"; + out << "Failed - duplicate UUID at iteration " << i << "\n"; break; } else @@ -278,21 +294,22 @@ void handleDiagnostics (std::string& outs) } if (uuids.size () >= 1000) - std::cout << "1000 unique UUIDs generated.\n"; + out << "1000 unique UUIDs generated.\n"; // Determine terminal details. const char* term = getenv ("TERM"); - std::cout << " $TERM: " - << (term ? term : "-none=") - << " (" - << context.getWidth () - << "x" - << context.getHeight () - << ")\n"; + out << " $TERM: " + << (term ? term : "-none=") + << " (" + << context.getWidth () + << "x" + << context.getHeight () + << ")\n"; } - std::cout << "\n"; + out << "\n"; + output = out.str (); + return 0; } //////////////////////////////////////////////////////////////////////////////// - diff --git a/src/commands/CmdDiagnostics.h b/src/commands/CmdDiagnostics.h new file mode 100644 index 000000000..2df5b7c7a --- /dev/null +++ b/src/commands/CmdDiagnostics.h @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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_CMDDIAGNOSTICS +#define INCLUDED_CMDDIAGNOSTICS +#define L10N // Localization complete. + +#include +#include + +class CmdDiagnostics : public Command +{ +public: + CmdDiagnostics (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 58c7654bd..1be059478 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -242,10 +242,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output) row = view.addRow (); view.set (row, 1, "task config [name [value | '']]"); view.set (row, 2, "Add, modify and remove settings in the task configuration."); - - row = view.addRow (); - view.set (row, 1, "task diagnostics"); - view.set (row, 2, "Information needed when reporting a problem."); */ output = "\n" diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index f4b1af9b4..441abba39 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -47,16 +48,17 @@ void Command::factory (std::map & all) { Command* c; + c = new CmdCompletionVersion (); all[c->keyword ()] = c; + c = new CmdDiagnostics (); all[c->keyword ()] = c; c = new CmdExec (); all[c->keyword ()] = c; c = new CmdHelp (); all[c->keyword ()] = c; - c = new CmdInstall (); all[c->keyword ()] = c; c = new CmdInfo (); all[c->keyword ()] = c; + c = new CmdInstall (); all[c->keyword ()] = c; c = new CmdLogo (); all[c->keyword ()] = c; c = new CmdShow (); 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; - c = new CmdCompletionVersion (); 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 a425b386a..1614c789e 100644 --- a/src/main.h +++ b/src/main.h @@ -88,9 +88,6 @@ int deltaTags (Task&); int deltaAttributes (Task&); int deltaSubstitutions (Task&); -// diag.cpp -void handleDiagnostics (std::string&); - // edit.cpp int handleEdit (std::string&);