- Localized 'diagnostics' command.
This commit is contained in:
Paul Beckingham 2011-10-01 12:24:14 -04:00
parent a59a2f7234
commit 2c69d4871d
2 changed files with 36 additions and 15 deletions

View file

@ -25,6 +25,8 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
@ -173,11 +175,13 @@ int CmdDiagnostics::execute (std::string& output)
<< "\n\n"; << "\n\n";
// Config: .taskrc found, readable, writable // Config: .taskrc found, readable, writable
out << bold.colorize ("Configuration") out << bold.colorize (STRING_CMD_DIAG_CONFIG)
<< "\n" << "\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 ()
<< ", " << context.config._original_file.size () << " bytes" ? STRING_CMD_DIAG_FOUND
: STRING_CMD_DIAG_MISSING)
<< ", " << context.config._original_file.size () << " " << "bytes"
<< ", mode " << ", mode "
<< std::setbase (8) << std::setbase (8)
<< context.config._original_file.mode () << context.config._original_file.mode ()
@ -185,8 +189,10 @@ int CmdDiagnostics::execute (std::string& output)
// 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"));
out << " Data: " << location._data out << " Data: " << location._data << " "
<< (location.exists () ? " (found)" : " (missing)") << (location.exists ()
? STRING_CMD_DIAG_FOUND
: STRING_CMD_DIAG_MISSING)
<< ", " << (location.is_directory () ? "dir" : "?") << ", " << (location.is_directory () ? "dir" : "?")
<< ", mode " << ", mode "
<< std::setbase (8) << std::setbase (8)
@ -194,7 +200,9 @@ int CmdDiagnostics::execute (std::string& output)
<< "\n"; << "\n";
out << " Locking: " out << " Locking: "
<< (context.config.getBoolean ("locking") ? "Enabled" : "Disabled") << (context.config.getBoolean ("locking")
? STRING_CMD_DIAG_ENABLED
: STRING_CMD_DIAG_DISABLED)
<< "\n"; << "\n";
// Determine rc.editor/$EDITOR/$VISUAL. // Determine rc.editor/$EDITOR/$VISUAL.
@ -209,7 +217,7 @@ int CmdDiagnostics::execute (std::string& output)
out << "\n"; out << "\n";
// External commands. // External commands.
out << bold.colorize ("External Utilities") out << bold.colorize (STRING_CMD_DIAG_EXTERNAL)
<< "\n"; << "\n";
{ {
std::vector <std::string> matches; std::vector <std::string> matches;
@ -223,7 +231,9 @@ int CmdDiagnostics::execute (std::string& output)
RX r ("usage", false); RX r ("usage", false);
if (p) if (p)
out << " scp: " out << " scp: "
<< (r.match (buffer) ? "found" : "n/a") << (r.match (buffer)
? STRING_CMD_DIAG_FOUND
: STRING_CMD_DIAG_MISSING)
<< "\n"; << "\n";
} }
@ -239,7 +249,7 @@ int CmdDiagnostics::execute (std::string& output)
matches.clear (); matches.clear ();
r.match (matches, buffer); r.match (matches, buffer);
out << " rsync: " out << " rsync: "
<< (matches.size () ? matches[0] : "n/a") << (matches.size () ? matches[0] : STRING_CMD_DIAG_MISSING)
<< "\n"; << "\n";
} }
} }
@ -256,7 +266,7 @@ int CmdDiagnostics::execute (std::string& output)
matches.clear (); matches.clear ();
r.match (matches, buffer); r.match (matches, buffer);
out << " curl: " out << " curl: "
<< (matches.size () ? matches[0] : "n/a") << (matches.size () ? matches[0] : STRING_CMD_DIAG_MISSING)
<< "\n"; << "\n";
} }
} }
@ -265,7 +275,7 @@ int CmdDiagnostics::execute (std::string& output)
} }
// Generate 1000 UUIDs and verify they are all unique. // Generate 1000 UUIDs and verify they are all unique.
out << bold.colorize ("Tests") out << bold.colorize (STRING_CMD_DIAG_TESTS)
<< "\n"; << "\n";
{ {
out << " UUID gen: "; out << " UUID gen: ";
@ -276,7 +286,7 @@ int CmdDiagnostics::execute (std::string& output)
id = uuid (); id = uuid ();
if (std::find (uuids.begin (), uuids.end (), id) != uuids.end ()) if (std::find (uuids.begin (), uuids.end (), id) != uuids.end ())
{ {
out << "Failed - duplicate UUID at iteration " << i << "\n"; out << format (STRING_CMD_DIAG_UUID_BAD, i) << "\n";
break; break;
} }
else else
@ -284,12 +294,12 @@ int CmdDiagnostics::execute (std::string& output)
} }
if (uuids.size () >= 1000) if (uuids.size () >= 1000)
out << "1000 unique UUIDs generated.\n"; out << STRING_CMD_DIAG_UUID_GOOD << "\n";
// Determine terminal details. // Determine terminal details.
const char* term = getenv ("TERM"); const char* term = getenv ("TERM");
out << " $TERM: " out << " $TERM: "
<< (term ? term : "-none=") << (term ? term : STRING_CMD_DIAG_NONE)
<< " (" << " ("
<< context.getWidth () << context.getWidth ()
<< "x" << "x"

View file

@ -345,6 +345,17 @@
#define STRING_CMD_DIAG_FEATURES "Build Features" #define STRING_CMD_DIAG_FEATURES "Build Features"
#define STRING_CMD_DIAG_BUILT "Built" #define STRING_CMD_DIAG_BUILT "Built"
#define STRING_CMD_DIAG_COMMIT "Commit" #define STRING_CMD_DIAG_COMMIT "Commit"
#define STRING_CMD_DIAG_FOUND "(found)"
#define STRING_CMD_DIAG_MISSING "(missing)"
#define STRING_CMD_DIAG_ENABLED "Enabled"
#define STRING_CMD_DIAG_DISABLED "Disabled"
#define STRING_CMD_DIAG_CONFIG "Configuration"
#define STRING_CMD_DIAG_EXTERNAL "External Utilities"
#define STRING_CMD_DIAG_TESTS "Tests"
#define STRING_CMD_DIAG_UUID_GOOD "1000 unique UUIDs generated."
#define STRING_CMD_DIAG_UUID_BAD "Failed - duplicate UUID at iteration {1}"
#define STRING_CMD_DIAG_NONE "-none-"
#define STRING_CMD_PUSH_USAGE "Pushes the local *.data files to the URL." #define STRING_CMD_PUSH_USAGE "Pushes the local *.data files to the URL."
#define STRING_CMD_PUSH_SAME "Cannot push files when the source and destination are the same." #define STRING_CMD_PUSH_SAME "Cannot push files when the source and destination are the same."
#define STRING_CMD_PUSH_NONLOCAL "The uri '{1}' is not a local directory." #define STRING_CMD_PUSH_NONLOCAL "The uri '{1}' is not a local directory."