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
command.cpp
dependency.cpp
diag.cpp
edit.cpp
export.cpp
feedback.cpp

View file

@ -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" ||

View file

@ -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); }

View file

@ -7,6 +7,7 @@ include_directories (${CMAKE_SOURCE_DIR}
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

View file

@ -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,18 +42,35 @@ 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" << 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"
@ -83,7 +92,8 @@ void handleDiagnostics (std::string& outs)
<< "\n\n";
// Compiler.
std::cout << "Compiler\n"
out << bold.colorize ("Compiler")
<< "\n"
#ifdef __VERSION__
<< " Version: " << __VERSION__ << "\n"
#endif
@ -115,9 +125,10 @@ void handleDiagnostics (std::string& outs)
<< " +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
#else
@ -125,7 +136,7 @@ void handleDiagnostics (std::string& outs)
#endif
<< "\n";
std::cout << " Lua: "
out << " Lua: "
#ifdef HAVE_LIBLUA
<< LUA_RELEASE
#else
@ -133,7 +144,9 @@ void handleDiagnostics (std::string& outs)
#endif
<< "\n\n";
std::cout << "Build Features\n"
out << bold.colorize ("Build Features")
<< "\n"
// Build date.
<< " Built: " << __DATE__ << " " << __TIME__ << "\n"
#ifdef HAVE_COMMIT
@ -169,7 +182,8 @@ void handleDiagnostics (std::string& outs)
<< "\n\n";
// Config: .taskrc found, readable, writable
std::cout << "Configuration\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"
@ -180,7 +194,7 @@ void handleDiagnostics (std::string& outs)
// Config: data.location found, readable, writable
File location (context.config.get ("data.location"));
std::cout << " Data: " << location.data
out << " Data: " << location.data
<< (location.exists () ? " (found)" : " (missing)")
<< ", " << (location.is_directory () ? "dir" : "?")
<< ", mode "
@ -188,27 +202,28 @@ void handleDiagnostics (std::string& outs)
<< location.mode ()
<< "\n";
std::cout << " Locking: "
out << " Locking: "
<< (context.config.getBoolean ("locking") ? "Enabled" : "Disabled")
<< "\n";
std::cout << " Regex: "
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 <std::string> matches;
char buffer [1024] = {0};
@ -219,7 +234,7 @@ void handleDiagnostics (std::string& outs)
pclose (fp);
if (p)
std::cout << " scp: "
out << " scp: "
<< (regexMatch (buffer, "usage") ? "found" : "n/a")
<< "\n";
}
@ -234,7 +249,7 @@ void handleDiagnostics (std::string& outs)
{
matches.clear ();
regexMatch (matches, buffer, "version ([0-9]+\\.[0-9]+\\.[0-9]+)");
std::cout << " rsync: "
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: "
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 <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,11 +294,11 @@ 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: "
out << " $TERM: "
<< (term ? term : "-none=")
<< " ("
<< context.getWidth ()
@ -291,8 +307,9 @@ void handleDiagnostics (std::string& outs)
<< ")\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 ();
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"

View file

@ -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;

View file

@ -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&);