Repository: kudu
Updated Branches:
refs/heads/master d4b6520b6 -> 07c1b00c3
tools: wrap descriptions
Wraps the help and usage output on a 78-column width so that it's much more
readable.
New output:
todd@todd-ThinkPad-T540p:~/git/kudu$ ./build/latest/bin/kudu cluster
Usage: ./build/latest/bin/kudu cluster <command> [<args>]
<command> can be one of the following:
ksck Check the health of a Kudu cluster. By default, ksck checks that
master and tablet server processes are running, and that table
metadata is consistent. Use the 'checksum' flag to check that tablet
data is consistent (also see the 'tables' and 'tablets' flags). Use
the 'checksum_snapshot' along with 'checksum' if the table or tablets
are actively receiving inserts or updates.
todd@todd-ThinkPad-T540p:~/git/kudu$ ./build/latest/bin/kudu cluster ksck --help
Usage: ./build/latest/bin/kudu cluster ksck <master_address> [-checksum_scan]
[-nochecksum_snapshot] [-tables=<tables>] [-tablets=<tablets>]
[-color=<color>]
Check the health of a Kudu cluster. By default, ksck checks that master and
tablet server processes are running, and that table metadata is consistent.
Use the 'checksum' flag to check that tablet data is consistent (also see the
'tables' and 'tablets' flags). Use the 'checksum_snapshot' along with
'checksum' if the table or tablets are actively receiving inserts or updates.
master_address (Kudu Master RPC address of form hostname:port)
type: string default: ""
-checksum_scan (Perform a checksum scan on data in the cluster.) type: bool
default: false
-checksum_snapshot (Should the checksum scanner use a snapshot scan)
type: bool default: true
-tables (Tables to check (comma-separated list of names). If not specified,
checks all tables.) type: string default: ""
-tablets (Tablets to check (comma-separated list of IDs) If not specified,
checks all tablets.) type: string default: ""
-color (Specifies whether ksck output is colorized. The default value
'auto' colorizes output if the output is a terminal. The other valid
values are 'always' or 'never'.) type: string default: "auto"
Change-Id: Ie63b72e1e1a3479819730c348f5a0f00a7164d02
Reviewed-on: http://gerrit.cloudera.org:8080/4130
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/07c1b00c
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/07c1b00c
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/07c1b00c
Branch: refs/heads/master
Commit: 07c1b00c33b9f0142b0a04b280f48c8621f4e232
Parents: d4b6520
Author: Todd Lipcon <[email protected]>
Authored: Thu Aug 25 19:22:20 2016 -0700
Committer: Todd Lipcon <[email protected]>
Committed: Fri Aug 26 20:58:00 2016 +0000
----------------------------------------------------------------------
src/kudu/tools/tool_action.cc | 67 +++++++++++++++++++++++++++++++++-----
1 file changed, 58 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/07c1b00c/src/kudu/tools/tool_action.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action.cc b/src/kudu/tools/tool_action.cc
index 616e6a6..86e3b93 100644
--- a/src/kudu/tools/tool_action.cc
+++ b/src/kudu/tools/tool_action.cc
@@ -21,12 +21,12 @@
#include <iomanip>
#include <memory>
#include <string>
-#include <strstream>
#include <unordered_map>
#include <utility>
#include <vector>
#include "kudu/gutil/strings/join.h"
+#include "kudu/gutil/strings/split.h"
#include "kudu/gutil/strings/substitute.h"
using std::string;
@@ -65,6 +65,51 @@ string BuildUsageString(const vector<Mode*>& chain) {
return Substitute("Usage: $0", modes);
}
+
+// Append 'to_append' to 'dst', but hard-wrapped at 78 columns.
+// After any newline, 'continuation_indent' spaces are prepended.
+void AppendHardWrapped(StringPiece to_append,
+ int continuation_indent,
+ string* dst) {
+ const int kWrapColumns = 78;
+ DCHECK_LT(continuation_indent, kWrapColumns);
+
+ // The string we're appending to might not be already at a newline.
+ int last_line_length = 0;
+ auto newline_pos = dst->rfind('\n');
+ if (newline_pos != string::npos) {
+ last_line_length = dst->size() - newline_pos;
+ }
+
+ // Iterate through the words deciding where to wrap.
+ vector<StringPiece> words = strings::Split(to_append, " ");
+ if (words.empty()) return;
+
+ for (const auto& word : words) {
+ // If the next word won't fit on this line, break before we append it.
+ if (last_line_length + word.size() > kWrapColumns) {
+ dst->push_back('\n');
+ for (int i = 0; i < continuation_indent; i++) {
+ dst->push_back(' ');
+ }
+ last_line_length = continuation_indent;
+ }
+ word.AppendToString(dst);
+ dst->push_back(' ');
+ last_line_length += word.size() + 1;
+ }
+
+ // Remove the extra space that we added at the end.
+ dst->resize(dst->size() - 1);
+}
+
+string SpacePad(StringPiece s, int len) {
+ if (s.size() >= len) {
+ return s.ToString();
+ }
+ return string(len - s.size(), ' ' ) + s.ToString();
+}
+
} // anonymous namespace
ModeBuilder::ModeBuilder(const Label& label)
@@ -91,9 +136,9 @@ unique_ptr<Mode> ModeBuilder::Build() {
// Get help for this mode, passing in its parent mode chain.
string Mode::BuildHelp(const vector<Mode*>& chain) const {
- std::ostringstream msg;
- msg << Substitute("$0 <command> [<args>]\n\n", BuildUsageString(chain));
- msg << "<command> can be one of the following:\n";
+ string msg;
+ msg += Substitute("$0 <command> [<args>]\n\n", BuildUsageString(chain));
+ msg += "<command> can be one of the following:\n";
vector<pair<string, string>> line_pairs;
int max_command_len = 0;
@@ -107,11 +152,13 @@ string Mode::BuildHelp(const vector<Mode*>& chain) const {
}
for (const auto& lp : line_pairs) {
- msg << " " << std::setw(max_command_len) << lp.first;
- msg << " " << lp.second << "\n";
+ msg += " " + SpacePad(lp.first, max_command_len);
+ msg += " ";
+ AppendHardWrapped(lp.second, max_command_len + 5, &msg);
+ msg += "\n";
}
- return msg.str();
+ return msg;
}
Mode::Mode() {
@@ -197,9 +244,11 @@ string Action::BuildHelp(const vector<Mode*>& chain) const
{
}
desc_msg += google::DescribeOneFlag(gflag_info);
}
- string msg = usage_msg;
+ string msg;
+ AppendHardWrapped(usage_msg, 8, &msg);
+ msg += "\n\n";
+ AppendHardWrapped(label_.description, 0, &msg);
msg += "\n\n";
- msg += Substitute("$0\n", label_.description);
msg += desc_msg;
return msg;
}