Commands - diag

- Migrated diag.cpp to CmdDiagnostics.
This commit is contained in:
Paul Beckingham
2011-05-28 13:15:19 -04:00
parent 0ce198ab8c
commit ed97fcc108
9 changed files with 184 additions and 133 deletions

View File

@@ -43,7 +43,6 @@ set (task_SRCS API.cpp API.h
burndown.cpp burndown.cpp
command.cpp command.cpp
dependency.cpp dependency.cpp
diag.cpp
edit.cpp edit.cpp
export.cpp export.cpp
feedback.cpp feedback.cpp

View File

@@ -158,7 +158,6 @@ void Cmd::load ()
commands.push_back ("colors"); commands.push_back ("colors");
commands.push_back ("config"); commands.push_back ("config");
commands.push_back ("delete"); commands.push_back ("delete");
commands.push_back ("diagnostics");
commands.push_back ("done"); commands.push_back ("done");
commands.push_back ("duplicate"); commands.push_back ("duplicate");
commands.push_back ("edit"); commands.push_back ("edit");
@@ -256,7 +255,6 @@ bool Cmd::isReadOnlyCommand ()
command == "ids" || command == "ids" ||
command == "calendar" || command == "calendar" ||
command == "colors" || command == "colors" ||
command == "diagnostics" ||
command == "config" || command == "config" ||
command == "help" || command == "help" ||
command == "projects" || command == "projects" ||

View File

@@ -283,7 +283,6 @@ int Context::dispatch (std::string &out)
handleMerge (out); } handleMerge (out); }
else if (cmd.command == "push") { handlePush (out); } else if (cmd.command == "push") { handlePush (out); }
else if (cmd.command == "pull") { handlePull (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 == "count") { rc = handleCount (out); }
else if (cmd.command == "ids") { rc = handleIds (out); } else if (cmd.command == "ids") { rc = handleIds (out); }
else if (cmd.command == "_projects") { rc = handleCompletionProjects (out); } else if (cmd.command == "_projects") { rc = handleCompletionProjects (out); }

View File

@@ -5,17 +5,18 @@ include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/columns ${CMAKE_SOURCE_DIR}/src/columns
${TASK_INCLUDE_DIRS}) ${TASK_INCLUDE_DIRS})
set (commands_SRCS Command.cpp Command.h set (commands_SRCS Command.cpp Command.h
CmdCustom.cpp CmdCustom.h CmdCustom.cpp CmdCustom.h
CmdExec.cpp CmdExec.h CmdDiagnostics.cpp CmdDiagnostics.h
CmdHelp.cpp CmdHelp.h CmdExec.cpp CmdExec.h
CmdInfo.cpp CmdInfo.h CmdHelp.cpp CmdHelp.h
CmdInstall.cpp CmdInstall.h CmdInfo.cpp CmdInfo.h
CmdLogo.cpp CmdLogo.h CmdInstall.cpp CmdInstall.h
CmdShow.cpp CmdShow.h CmdLogo.cpp CmdLogo.h
CmdTags.cpp CmdTags.h CmdShow.cpp CmdShow.h
CmdTip.cpp CmdTip.h CmdTags.cpp CmdTags.h
CmdVersion.cpp CmdVersion.h) CmdTip.cpp CmdTip.h
CmdVersion.cpp CmdVersion.h)
add_library (commands STATIC ${commands_SRCS}) add_library (commands STATIC ${commands_SRCS})

View File

@@ -25,18 +25,10 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <rx.h> #include <rx.h>
#include <File.h> #include <Context.h>
#include <main.h>
#include <util.h> #include <util.h>
#include <cmake.h> #include <cmake.h>
#ifdef HAVE_COMMIT #ifdef HAVE_COMMIT
@@ -50,165 +42,188 @@ extern "C"
} }
#endif #endif
#include <CmdDiagnostics.h>
extern Context context; 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. // This command will generate output that is intended to help diagnose problems.
// //
// Although this will change over time, initially this command will answer the // Although this will change over time, initially this command will answer the
// kind of questions we always have to ask whenever something is wrong. // 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) #if defined (DARWIN)
"Darwin" "Darwin"
#elif defined (SOLARIS) #elif defined (SOLARIS)
"Solaris" "Solaris"
#elif defined (CYGWIN) #elif defined (CYGWIN)
"Cygwin" "Cygwin"
#elif defined (OPENBSD) #elif defined (OPENBSD)
"OpenBSD" "OpenBSD"
#elif defined (HAIKU) #elif defined (HAIKU)
"Haiku" "Haiku"
#elif defined (FREEBSD) #elif defined (FREEBSD)
"FreeBSD" "FreeBSD"
#elif defined (LINUX) #elif defined (LINUX)
"Linux" "Linux"
#else #else
"<unknown>" "<unknown>"
#endif #endif
<< "\n\n"; << "\n\n";
// Compiler. // Compiler.
std::cout << "Compiler\n" out << bold.colorize ("Compiler")
<< "\n"
#ifdef __VERSION__ #ifdef __VERSION__
<< " Version: " << __VERSION__ << "\n" << " Version: " << __VERSION__ << "\n"
#endif #endif
<< " Caps:" << " Caps:"
#ifdef __STDC__ #ifdef __STDC__
<< " +stdc" << " +stdc"
#endif #endif
#ifdef __STDC_HOSTED__ #ifdef __STDC_HOSTED__
<< " +stdc_hosted" << " +stdc_hosted"
#endif #endif
#ifdef __STDC_VERSION__ #ifdef __STDC_VERSION__
<< " +" << __STDC_VERSION__ << " +" << __STDC_VERSION__
#endif #endif
#ifdef _POSIX_VERSION #ifdef _POSIX_VERSION
<< " +" << _POSIX_VERSION << " +" << _POSIX_VERSION
#endif #endif
#ifdef _POSIX2_C_VERSION #ifdef _POSIX2_C_VERSION
<< " +" << _POSIX2_C_VERSION << " +" << _POSIX2_C_VERSION
#endif #endif
#ifdef _ILP32 #ifdef _ILP32
<< " +ILP32" << " +ILP32"
#endif #endif
#ifdef _LP64 #ifdef _LP64
<< " +LP64" << " +LP64"
#endif #endif
<< " +c" << sizeof (char) << " +c" << sizeof (char)
<< " +i" << sizeof (int) << " +i" << sizeof (int)
<< " +l" << sizeof (long) << " +l" << sizeof (long)
<< " +vp" << sizeof (void*) << " +vp" << sizeof (void*)
<< "\n\n"; << "\n\n";
std::cout << "Libraries\n"; out << bold.colorize ("Libraries")
<< "\n";
std::cout << " Readline: " out << " Readline: "
#ifdef HAVE_LIBREADLINE #ifdef HAVE_LIBREADLINE
<< std::setbase (16) << RL_READLINE_VERSION << std::setbase (16) << RL_READLINE_VERSION
#else #else
<< "n/a" << "n/a"
#endif #endif
<< "\n"; << "\n";
std::cout << " Lua: " out << " Lua: "
#ifdef HAVE_LIBLUA #ifdef HAVE_LIBLUA
<< LUA_RELEASE << LUA_RELEASE
#else #else
<< "n/a" << "n/a"
#endif #endif
<< "\n\n"; << "\n\n";
out << bold.colorize ("Build Features")
<< "\n"
std::cout << "Build Features\n"
// Build date. // Build date.
<< " Built: " << __DATE__ << " " << __TIME__ << "\n" << " Built: " << __DATE__ << " " << __TIME__ << "\n"
#ifdef HAVE_COMMIT #ifdef HAVE_COMMIT
<< " Commit: " << COMMIT << "\n" << " Commit: " << COMMIT << "\n"
#endif #endif
#ifdef HAVE_CMAKE #ifdef HAVE_CMAKE
<< " CMake: " << CMAKE_VERSION << "\n" << " CMake: " << CMAKE_VERSION << "\n"
#endif #endif
<< " Caps:" << " Caps:"
#ifdef HAVE_LIBPTHREAD #ifdef HAVE_LIBPTHREAD
<< " +pthreads" << " +pthreads"
#else #else
<< " -pthreads" << " -pthreads"
#endif #endif
#ifdef HAVE_SRANDOM #ifdef HAVE_SRANDOM
<< " +srandom" << " +srandom"
#else #else
<< " -srandom" << " -srandom"
#endif #endif
#ifdef HAVE_RANDOM #ifdef HAVE_RANDOM
<< " +random" << " +random"
#else #else
<< " -random" << " -random"
#endif #endif
#ifdef HAVE_UUID #ifdef HAVE_UUID
<< " +uuid" << " +uuid"
#else #else
<< " -uuid" << " -uuid"
#endif #endif
<< "\n\n"; << "\n\n";
// Config: .taskrc found, readable, writable // Config: .taskrc found, readable, writable
std::cout << "Configuration\n" out << bold.colorize ("Configuration")
<< " File: " << context.config.original_file.data << "\n"
<< (context.config.original_file.exists () ? " (found)" : " (missing)") << " File: " << context.config.original_file.data
<< ", " << context.config.original_file.size () << " bytes" << (context.config.original_file.exists () ? " (found)" : " (missing)")
<< ", mode " << ", " << context.config.original_file.size () << " bytes"
<< std::setbase (8) << ", mode "
<< context.config.original_file.mode () << std::setbase (8)
<< "\n"; << context.config.original_file.mode ()
<< "\n";
// Config: data.location found, readable, writable // Config: data.location found, readable, writable
File location (context.config.get ("data.location")); File location (context.config.get ("data.location"));
std::cout << " Data: " << location.data out << " Data: " << location.data
<< (location.exists () ? " (found)" : " (missing)") << (location.exists () ? " (found)" : " (missing)")
<< ", " << (location.is_directory () ? "dir" : "?") << ", " << (location.is_directory () ? "dir" : "?")
<< ", mode " << ", mode "
<< std::setbase (8) << std::setbase (8)
<< location.mode () << location.mode ()
<< "\n"; << "\n";
std::cout << " Locking: " out << " Locking: "
<< (context.config.getBoolean ("locking") ? "Enabled" : "Disabled") << (context.config.getBoolean ("locking") ? "Enabled" : "Disabled")
<< "\n"; << "\n";
std::cout << " Regex: " out << " Regex: "
<< (context.config.getBoolean ("regex") ? "Enabled" : "Disabled") << (context.config.getBoolean ("regex") ? "Enabled" : "Disabled")
<< "\n"; << "\n";
// Determine rc.editor/$EDITOR/$VISUAL. // Determine rc.editor/$EDITOR/$VISUAL.
char* peditor; char* peditor;
if (context.config.get ("editor") != "") 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) else if ((peditor = getenv ("VISUAL")) != NULL)
std::cout << " $VISUAL: " << peditor << "\n"; out << " $VISUAL: " << peditor << "\n";
else if ((peditor = getenv ("EDITOR")) != NULL) else if ((peditor = getenv ("EDITOR")) != NULL)
std::cout << " $EDITOR: " << peditor << "\n"; out << " $EDITOR: " << peditor << "\n";
std::cout << "\n"; out << "\n";
// External commands. // External commands.
std::cout << "External Utilities\n"; out << bold.colorize ("External Utilities")
<< "\n";
{ {
std::vector <std::string> matches; std::vector <std::string> matches;
char buffer [1024] = {0}; char buffer [1024] = {0};
@@ -219,9 +234,9 @@ void handleDiagnostics (std::string& outs)
pclose (fp); pclose (fp);
if (p) if (p)
std::cout << " scp: " out << " scp: "
<< (regexMatch (buffer, "usage") ? "found" : "n/a") << (regexMatch (buffer, "usage") ? "found" : "n/a")
<< "\n"; << "\n";
} }
if ((fp = popen ("rsync --version 2>&1", "r"))) if ((fp = popen ("rsync --version 2>&1", "r")))
@@ -234,9 +249,9 @@ void handleDiagnostics (std::string& outs)
{ {
matches.clear (); matches.clear ();
regexMatch (matches, buffer, "version ([0-9]+\\.[0-9]+\\.[0-9]+)"); regexMatch (matches, buffer, "version ([0-9]+\\.[0-9]+\\.[0-9]+)");
std::cout << " rsync: " out << " rsync: "
<< (matches.size () ? matches[0] : "n/a") << (matches.size () ? matches[0] : "n/a")
<< "\n"; << "\n";
} }
} }
@@ -250,19 +265,20 @@ void handleDiagnostics (std::string& outs)
{ {
matches.clear (); matches.clear ();
regexMatch (matches, buffer, "curl ([0-9]+\\.[0-9]+\\.[0-9]+)"); regexMatch (matches, buffer, "curl ([0-9]+\\.[0-9]+\\.[0-9]+)");
std::cout << " curl: " out << " curl: "
<< (matches.size () ? matches[0] : "n/a") << (matches.size () ? matches[0] : "n/a")
<< "\n"; << "\n";
} }
} }
std::cout << "\n"; out << "\n";
} }
// Generate 1000 UUIDs and verify they are all unique. // 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 <std::string> uuids; std::vector <std::string> uuids;
std::string id; std::string id;
for (int i = 0; i < 1000; i++) for (int i = 0; i < 1000; i++)
@@ -270,7 +286,7 @@ void handleDiagnostics (std::string& outs)
id = uuid (); id = uuid ();
if (std::find (uuids.begin (), uuids.end (), id) != uuids.end ()) 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; break;
} }
else else
@@ -278,21 +294,22 @@ void handleDiagnostics (std::string& outs)
} }
if (uuids.size () >= 1000) if (uuids.size () >= 1000)
std::cout << "1000 unique UUIDs generated.\n"; out << "1000 unique UUIDs generated.\n";
// Determine terminal details. // Determine terminal details.
const char* term = getenv ("TERM"); const char* term = getenv ("TERM");
std::cout << " $TERM: " out << " $TERM: "
<< (term ? term : "-none=") << (term ? term : "-none=")
<< " (" << " ("
<< context.getWidth () << context.getWidth ()
<< "x" << "x"
<< context.getHeight () << context.getHeight ()
<< ")\n"; << ")\n";
} }
std::cout << "\n"; out << "\n";
output = out.str ();
return 0;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -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 <string>
#include <Command.h>
class CmdDiagnostics : public Command
{
public:
CmdDiagnostics ();
int execute (const std::string&, std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View File

@@ -242,10 +242,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output)
row = view.addRow (); row = view.addRow ();
view.set (row, 1, "task config [name [value | '']]"); view.set (row, 1, "task config [name [value | '']]");
view.set (row, 2, "Add, modify and remove settings in the task configuration."); 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" output = "\n"

View File

@@ -29,6 +29,7 @@
#include <vector> #include <vector>
#include <Command.h> #include <Command.h>
#include <CmdCustom.h> #include <CmdCustom.h>
#include <CmdDiagnostics.h>
#include <CmdExec.h> #include <CmdExec.h>
#include <CmdHelp.h> #include <CmdHelp.h>
#include <CmdInfo.h> #include <CmdInfo.h>
@@ -47,16 +48,17 @@ void Command::factory (std::map <std::string, Command*>& all)
{ {
Command* c; 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 CmdExec (); all[c->keyword ()] = c;
c = new CmdHelp (); 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 CmdInfo (); all[c->keyword ()] = c;
c = new CmdInstall (); all[c->keyword ()] = c;
c = new CmdLogo (); all[c->keyword ()] = c; c = new CmdLogo (); all[c->keyword ()] = c;
c = new CmdShow (); all[c->keyword ()] = c; c = new CmdShow (); all[c->keyword ()] = c;
c = new CmdTags (); all[c->keyword ()] = c; c = new CmdTags (); all[c->keyword ()] = c;
c = new CmdTip (); all[c->keyword ()] = c; c = new CmdTip (); all[c->keyword ()] = c;
c = new CmdVersion (); 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. // Instantiate a command object for each custom report.
std::vector <std::string> variables; std::vector <std::string> variables;

View File

@@ -88,9 +88,6 @@ int deltaTags (Task&);
int deltaAttributes (Task&); int deltaAttributes (Task&);
int deltaSubstitutions (Task&); int deltaSubstitutions (Task&);
// diag.cpp
void handleDiagnostics (std::string&);
// edit.cpp // edit.cpp
int handleEdit (std::string&); int handleEdit (std::string&);