// Copyright 2008-present Facebook. All Rights Reserved. #include "leveldb/ldb_tool.h" #include "util/ldb_cmd.h" namespace leveldb { class LDBCommandRunner { public: static void PrintHelp(const char* exec_name) { string ret; ret.append("ldb - LevelDB Tool"); ret.append("\n\n"); ret.append("commands MUST specify --" + LDBCommand::ARG_DB + "= when necessary\n"); ret.append("\n"); ret.append("The following optional parameters control if keys/values are " "input/output as hex or as plain strings:\n"); ret.append(" --" + LDBCommand::ARG_KEY_HEX + " : Keys are input/output as hex\n"); ret.append(" --" + LDBCommand::ARG_VALUE_HEX + " : Values are input/output as hex\n"); ret.append(" --" + LDBCommand::ARG_HEX + " : Both keys and values are input/output as hex\n"); ret.append("\n"); ret.append("The following optional parameters control the database " "internals:\n"); ret.append(" --" + LDBCommand::ARG_BLOOM_BITS + "=\n"); ret.append(" --" + LDBCommand::ARG_COMPRESSION_TYPE + "=\n"); ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE + "=\n"); ret.append(" --" + LDBCommand::ARG_AUTO_COMPACTION + "=\n"); ret.append(" --" + LDBCommand::ARG_WRITE_BUFFER_SIZE + "=\n"); ret.append(" --" + LDBCommand::ARG_FILE_SIZE + "=\n"); ret.append("\n\n"); ret.append("Data Access Commands:\n"); PutCommand::Help(ret); GetCommand::Help(ret); BatchPutCommand::Help(ret); ScanCommand::Help(ret); DeleteCommand::Help(ret); DBQuerierCommand::Help(ret); ApproxSizeCommand::Help(ret); ret.append("\n\n"); ret.append("Admin Commands:\n"); WALDumperCommand::Help(ret); CompactorCommand::Help(ret); ReduceDBLevelsCommand::Help(ret); DBDumperCommand::Help(ret); DBLoaderCommand::Help(ret); ManifestDumpCommand::Help(ret); fprintf(stderr, "%s\n", ret.c_str()); } static void RunCommand(int argc, char** argv, Options options) { if (argc <= 2) { PrintHelp(argv[0]); exit(1); } LDBCommand* cmdObj = LDBCommand::InitFromCmdLineArgs(argc, argv, options); if (cmdObj == nullptr) { fprintf(stderr, "Unknown command\n"); PrintHelp(argv[0]); exit(1); } if (!cmdObj->ValidateCmdLineOptions()) { exit(1); } cmdObj->Run(); LDBCommandExecuteResult ret = cmdObj->GetExecuteState(); fprintf(stderr, "%s\n", ret.ToString().c_str()); delete cmdObj; exit(ret.IsFailed()); } }; void LDBTool::Run(int argc, char** argv, Options options) { LDBCommandRunner::RunCommand(argc, argv, options); } } // namespace leveldb