Allow Users to change customized ldb tools' header in help printing

Summary: Closes https://github.com/facebook/rocksdb/pull/2018

Differential Revision: D4748448

Pulled By: siying

fbshipit-source-id: a54c2f9
This commit is contained in:
Siying Dong 2017-03-21 17:22:10 -07:00 committed by Facebook Github Bot
parent a2a883318b
commit 17866ecc3a
3 changed files with 8 additions and 5 deletions

View File

@ -26,6 +26,8 @@ struct LDBOptions {
// Key formatter that converts a slice to a readable string.
// Default: Slice::ToString()
std::shared_ptr<SliceFormatter> key_formatter;
std::string print_help_header = "ldb - RocksDB Tool";
};
class LDBTool {

View File

@ -239,7 +239,7 @@ class LDBCommand {
class LDBCommandRunner {
public:
static void PrintHelp(const char* exec_name);
static void PrintHelp(const LDBOptions& ldb_options, const char* exec_name);
static void RunCommand(
int argc, char** argv, Options options, const LDBOptions& ldb_options,

View File

@ -12,10 +12,11 @@ namespace rocksdb {
LDBOptions::LDBOptions() {}
void LDBCommandRunner::PrintHelp(const char* exec_name) {
void LDBCommandRunner::PrintHelp(const LDBOptions& ldb_options,
const char* exec_name) {
std::string ret;
ret.append("ldb - LevelDB Tool");
ret.append(ldb_options.print_help_header);
ret.append("\n\n");
ret.append("commands MUST specify --" + LDBCommand::ARG_DB +
"=<full_path_to_db_directory> when necessary\n");
@ -91,7 +92,7 @@ void LDBCommandRunner::RunCommand(
int argc, char** argv, Options options, const LDBOptions& ldb_options,
const std::vector<ColumnFamilyDescriptor>* column_families) {
if (argc <= 2) {
PrintHelp(argv[0]);
PrintHelp(ldb_options, argv[0]);
exit(1);
}
@ -99,7 +100,7 @@ void LDBCommandRunner::RunCommand(
argc, argv, options, ldb_options, column_families);
if (cmdObj == nullptr) {
fprintf(stderr, "Unknown command\n");
PrintHelp(argv[0]);
PrintHelp(ldb_options, argv[0]);
exit(1);
}