mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-25 21:27:19 +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
|
burndown.cpp
|
||||||
command.cpp
|
command.cpp
|
||||||
dependency.cpp
|
dependency.cpp
|
||||||
diag.cpp
|
|
||||||
edit.cpp
|
edit.cpp
|
||||||
export.cpp
|
export.cpp
|
||||||
feedback.cpp
|
feedback.cpp
|
||||||
|
|
|
@ -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" ||
|
||||||
|
|
|
@ -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); }
|
||||||
|
|
|
@ -7,6 +7,7 @@ include_directories (${CMAKE_SOURCE_DIR}
|
||||||
|
|
||||||
set (commands_SRCS Command.cpp Command.h
|
set (commands_SRCS Command.cpp Command.h
|
||||||
CmdCustom.cpp CmdCustom.h
|
CmdCustom.cpp CmdCustom.h
|
||||||
|
CmdDiagnostics.cpp CmdDiagnostics.h
|
||||||
CmdExec.cpp CmdExec.h
|
CmdExec.cpp CmdExec.h
|
||||||
CmdHelp.cpp CmdHelp.h
|
CmdHelp.cpp CmdHelp.h
|
||||||
CmdInfo.cpp CmdInfo.h
|
CmdInfo.cpp CmdInfo.h
|
||||||
|
|
|
@ -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,18 +42,35 @@ 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[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)
|
#if defined (DARWIN)
|
||||||
"Darwin"
|
"Darwin"
|
||||||
|
@ -83,7 +92,8 @@ void handleDiagnostics (std::string& outs)
|
||||||
<< "\n\n";
|
<< "\n\n";
|
||||||
|
|
||||||
// Compiler.
|
// Compiler.
|
||||||
std::cout << "[1mCompiler[0m\n"
|
out << bold.colorize ("Compiler")
|
||||||
|
<< "\n"
|
||||||
#ifdef __VERSION__
|
#ifdef __VERSION__
|
||||||
<< " Version: " << __VERSION__ << "\n"
|
<< " Version: " << __VERSION__ << "\n"
|
||||||
#endif
|
#endif
|
||||||
|
@ -115,9 +125,10 @@ void handleDiagnostics (std::string& outs)
|
||||||
<< " +vp" << sizeof (void*)
|
<< " +vp" << sizeof (void*)
|
||||||
<< "\n\n";
|
<< "\n\n";
|
||||||
|
|
||||||
std::cout << "[1mLibraries[0m\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
|
||||||
|
@ -125,7 +136,7 @@ void handleDiagnostics (std::string& outs)
|
||||||
#endif
|
#endif
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
std::cout << " Lua: "
|
out << " Lua: "
|
||||||
#ifdef HAVE_LIBLUA
|
#ifdef HAVE_LIBLUA
|
||||||
<< LUA_RELEASE
|
<< LUA_RELEASE
|
||||||
#else
|
#else
|
||||||
|
@ -133,7 +144,9 @@ void handleDiagnostics (std::string& outs)
|
||||||
#endif
|
#endif
|
||||||
<< "\n\n";
|
<< "\n\n";
|
||||||
|
|
||||||
std::cout << "[1mBuild Features[0m\n"
|
out << bold.colorize ("Build Features")
|
||||||
|
<< "\n"
|
||||||
|
|
||||||
// Build date.
|
// Build date.
|
||||||
<< " Built: " << __DATE__ << " " << __TIME__ << "\n"
|
<< " Built: " << __DATE__ << " " << __TIME__ << "\n"
|
||||||
#ifdef HAVE_COMMIT
|
#ifdef HAVE_COMMIT
|
||||||
|
@ -169,7 +182,8 @@ void handleDiagnostics (std::string& outs)
|
||||||
<< "\n\n";
|
<< "\n\n";
|
||||||
|
|
||||||
// Config: .taskrc found, readable, writable
|
// Config: .taskrc found, readable, writable
|
||||||
std::cout << "[1mConfiguration[0m\n"
|
out << bold.colorize ("Configuration")
|
||||||
|
<< "\n"
|
||||||
<< " File: " << context.config.original_file.data
|
<< " File: " << context.config.original_file.data
|
||||||
<< (context.config.original_file.exists () ? " (found)" : " (missing)")
|
<< (context.config.original_file.exists () ? " (found)" : " (missing)")
|
||||||
<< ", " << context.config.original_file.size () << " bytes"
|
<< ", " << context.config.original_file.size () << " bytes"
|
||||||
|
@ -180,7 +194,7 @@ void handleDiagnostics (std::string& outs)
|
||||||
|
|
||||||
// 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 "
|
||||||
|
@ -188,27 +202,28 @@ void handleDiagnostics (std::string& outs)
|
||||||
<< 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 << "[1mExternal Utilities[0m\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,7 +234,7 @@ 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";
|
||||||
}
|
}
|
||||||
|
@ -234,7 +249,7 @@ 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 << "[1mTests[0m\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,11 +294,11 @@ 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 ()
|
||||||
|
@ -291,8 +307,9 @@ void handleDiagnostics (std::string& outs)
|
||||||
<< ")\n";
|
<< ")\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 ();
|
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"
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue