diff --git a/include/rocksdb/utilities/ldb_cmd.h b/include/rocksdb/utilities/ldb_cmd.h index abcb3082a..a3ecb03b0 100644 --- a/include/rocksdb/utilities/ldb_cmd.h +++ b/include/rocksdb/utilities/ldb_cmd.h @@ -53,10 +53,12 @@ class LDBCommand { static const std::string ARG_CREATE_IF_MISSING; static const std::string ARG_NO_VALUE; + template static LDBCommand* InitFromCmdLineArgs( const std::vector& args, const Options& options, const LDBOptions& ldb_options, - const std::vector* column_families); + const std::vector* column_families, + Selector selector = SelectCommand); static LDBCommand* InitFromCmdLineArgs( int argc, char** argv, const Options& options, @@ -105,6 +107,11 @@ class LDBCommand { static const char* DELIM; + static LDBCommand* SelectCommand( + const std::string& cmd, const std::vector& cmdParams, + const std::map& option_map, + const std::vector& flags); + protected: LDBCommandExecuteResult exec_state_; std::string db_path_; @@ -223,11 +230,6 @@ class LDBCommand { * Otherwise an exception is thrown. */ bool StringToBool(std::string val); - - static LDBCommand* SelectCommand( - const std::string& cmd, const std::vector& cmdParams, - const std::map& option_map, - const std::vector& flags); }; class LDBCommandRunner { diff --git a/tools/ldb_cmd.cc b/tools/ldb_cmd.cc index d1adb52ce..3ab137133 100644 --- a/tools/ldb_cmd.cc +++ b/tools/ldb_cmd.cc @@ -86,7 +86,8 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( for (int i = 1; i < argc; i++) { args.push_back(argv[i]); } - return InitFromCmdLineArgs(args, options, ldb_options, column_families); + return InitFromCmdLineArgs(args, options, ldb_options, column_families, + SelectCommand); } /** @@ -99,10 +100,12 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( * Command name is not included in args. * Returns nullptr if the command-line cannot be parsed. */ +template LDBCommand* LDBCommand::InitFromCmdLineArgs( const vector& args, const Options& options, const LDBOptions& ldb_options, - const std::vector* column_families) { + const std::vector* column_families, + Selector selector) { // --x=y command line arguments are added as x->y map entries. map option_map; @@ -137,12 +140,7 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( string cmd = cmdTokens[0]; vector cmdParams(cmdTokens.begin()+1, cmdTokens.end()); - LDBCommand* command = LDBCommand::SelectCommand( - cmd, - cmdParams, - option_map, - flags - ); + LDBCommand* command = selector(cmd, cmdParams, option_map, flags); if (command) { command->SetDBOptions(options); diff --git a/tools/reduce_levels_test.cc b/tools/reduce_levels_test.cc index d845733c9..ee0f9ca0a 100644 --- a/tools/reduce_levels_test.cc +++ b/tools/reduce_levels_test.cc @@ -93,8 +93,8 @@ Status ReduceLevelTest::OpenDB(bool create_if_missing, int num_levels) { bool ReduceLevelTest::ReduceLevels(int target_level) { std::vector args = rocksdb::ReduceDBLevelsCommand::PrepareArgs( dbname_, target_level, false); - LDBCommand* level_reducer = - LDBCommand::InitFromCmdLineArgs(args, Options(), LDBOptions(), nullptr); + LDBCommand* level_reducer = LDBCommand::InitFromCmdLineArgs( + args, Options(), LDBOptions(), nullptr, LDBCommand::SelectCommand); level_reducer->Run(); bool is_succeed = level_reducer->GetExecuteState().IsSucceed(); delete level_reducer;