mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Commands - diag
- Migrated diag.cpp to CmdDiagnostics.
This commit is contained in:
parent
0ce198ab8c
commit
ed97fcc108
9 changed files with 184 additions and 133 deletions
|
@ -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
|
||||
|
|
|
@ -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" ||
|
||||
|
|
|
@ -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); }
|
||||
|
|
|
@ -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})
|
||||
|
||||
|
|
|
@ -25,18 +25,10 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rx.h>
|
||||
#include <File.h>
|
||||
#include <main.h>
|
||||
#include <Context.h>
|
||||
#include <util.h>
|
||||
#include <cmake.h>
|
||||
#ifdef HAVE_COMMIT
|
||||
|
@ -50,165 +42,188 @@ extern "C"
|
|||
}
|
||||
#endif
|
||||
|
||||
#include <CmdDiagnostics.h>
|
||||
|
||||
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[1m" << PACKAGE_STRING << "[0m\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
|
||||
"<unknown>"
|
||||
"<unknown>"
|
||||
#endif
|
||||
<< "\n\n";
|
||||
<< "\n\n";
|
||||
|
||||
// Compiler.
|
||||
std::cout << "[1mCompiler[0m\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 << "[1mLibraries[0m\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 << "[1mBuild Features[0m\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 << "[1mConfiguration[0m\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 << "[1mExternal Utilities[0m\n";
|
||||
out << bold.colorize ("External Utilities")
|
||||
<< "\n";
|
||||
{
|
||||
std::vector <std::string> 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 << "[1mTests[0m\n";
|
||||
out << bold.colorize ("Tests")
|
||||
<< "\n";
|
||||
{
|
||||
std::cout << " UUID gen: ";
|
||||
out << " UUID gen: ";
|
||||
std::vector <std::string> 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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
42
src/commands/CmdDiagnostics.h
Normal file
42
src/commands/CmdDiagnostics.h
Normal 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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -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"
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <vector>
|
||||
#include <Command.h>
|
||||
#include <CmdCustom.h>
|
||||
#include <CmdDiagnostics.h>
|
||||
#include <CmdExec.h>
|
||||
#include <CmdHelp.h>
|
||||
#include <CmdInfo.h>
|
||||
|
@ -47,16 +48,17 @@ void Command::factory (std::map <std::string, Command*>& 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 <std::string> variables;
|
||||
|
|
|
@ -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&);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue