@ -102,12 +102,13 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs(
const std : : vector < std : : string > & args , const Options & options ,
const LDBOptions & ldb_options ,
const std : : vector < ColumnFamilyDescriptor > * column_families ,
const RocksDBLDBSelectFunc & selector ) {
// --x=y command line arguments are added as x->y map entries.
std : : map < std : : string , std : : string > option_map ;
// Command-line arguments of the form --hex end up in this array as hex
std : : vector < std : : string > flags ;
const std : : function < LDBCommand * ( const ParsedParams & ) > & selector ) {
// --x=y command line arguments are added as x->y map entries in
// parsed_params.option_map.
//
// Command-line arguments of the form --hex end up in this array as hex to
// parsed_params.flags
ParsedParams parsed_params ;
// Everything other than option_map and flags. Represents commands
// and their parameters. For eg: put key1 value1 go into this vector.
@ -120,10 +121,10 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs(
std : : vector < std : : string > splits = StringSplit ( arg , ' = ' ) ;
if ( splits . size ( ) = = 2 ) {
std : : string optionKey = splits [ 0 ] . substr ( OPTION_PREFIX . size ( ) ) ;
option_map [ optionKey ] = splits [ 1 ] ;
parsed_params . option_map [ optionKey ] = splits [ 1 ] ;
} else {
std : : string optionKey = splits [ 0 ] . substr ( OPTION_PREFIX . size ( ) ) ;
flags . push_back ( optionKey ) ;
parsed_params . flags . push_back ( optionKey ) ;
}
} else {
cmdTokens . push_back ( arg ) ;
@ -135,9 +136,10 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs(
return nullptr ;
}
std : : string cmd = cmdTokens [ 0 ] ;
std : : vector < std : : string > cmdParams ( cmdTokens . begin ( ) + 1 , cmdTokens . end ( ) ) ;
LDBCommand * command = selector ( cmd , cmdParams , option_map , flags ) ;
parsed_params . cmd = cmdTokens [ 0 ] ;
parsed_params . cmd_params . assign ( cmdTokens . begin ( ) + 1 , cmdTokens . end ( ) ) ;
LDBCommand * command = selector ( parsed_params ) ;
if ( command ) {
command - > SetDBOptions ( options ) ;
@ -146,50 +148,75 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs(
return command ;
}
LDBCommand * LDBCommand : : SelectCommand (
const std : : string & cmd , const std : : vector < std : : string > & cmdParams ,
const std : : map < std : : string , std : : string > & option_map ,
const std : : vector < std : : string > & flags ) {
if ( cmd = = GetCommand : : Name ( ) ) {
return new GetCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = PutCommand : : Name ( ) ) {
return new PutCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = BatchPutCommand : : Name ( ) ) {
return new BatchPutCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = ScanCommand : : Name ( ) ) {
return new ScanCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = DeleteCommand : : Name ( ) ) {
return new DeleteCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = ApproxSizeCommand : : Name ( ) ) {
return new ApproxSizeCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = DBQuerierCommand : : Name ( ) ) {
return new DBQuerierCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = CompactorCommand : : Name ( ) ) {
return new CompactorCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = WALDumperCommand : : Name ( ) ) {
return new WALDumperCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = ReduceDBLevelsCommand : : Name ( ) ) {
return new ReduceDBLevelsCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = ChangeCompactionStyleCommand : : Name ( ) ) {
return new ChangeCompactionStyleCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = DBDumperCommand : : Name ( ) ) {
return new DBDumperCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = DBLoaderCommand : : Name ( ) ) {
return new DBLoaderCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = ManifestDumpCommand : : Name ( ) ) {
return new ManifestDumpCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = ListColumnFamiliesCommand : : Name ( ) ) {
return new ListColumnFamiliesCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = CreateColumnFamilyCommand : : Name ( ) ) {
return new CreateColumnFamilyCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = DBFileDumperCommand : : Name ( ) ) {
return new DBFileDumperCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = InternalDumpCommand : : Name ( ) ) {
return new InternalDumpCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = CheckConsistencyCommand : : Name ( ) ) {
return new CheckConsistencyCommand ( cmdParams , option_map , flags ) ;
} else if ( cmd = = RepairCommand : : Name ( ) ) {
return new RepairCommand ( cmdParams , option_map , flags ) ;
LDBCommand * LDBCommand : : SelectCommand ( const ParsedParams & parsed_params ) {
if ( parsed_params . cmd = = GetCommand : : Name ( ) ) {
return new GetCommand ( parsed_params . cmd_params , parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = PutCommand : : Name ( ) ) {
return new PutCommand ( parsed_params . cmd_params , parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = BatchPutCommand : : Name ( ) ) {
return new BatchPutCommand ( parsed_params . cmd_params ,
parsed_params . option_map , parsed_params . flags ) ;
} else if ( parsed_params . cmd = = ScanCommand : : Name ( ) ) {
return new ScanCommand ( parsed_params . cmd_params , parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = DeleteCommand : : Name ( ) ) {
return new DeleteCommand ( parsed_params . cmd_params , parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = ApproxSizeCommand : : Name ( ) ) {
return new ApproxSizeCommand ( parsed_params . cmd_params ,
parsed_params . option_map , parsed_params . flags ) ;
} else if ( parsed_params . cmd = = DBQuerierCommand : : Name ( ) ) {
return new DBQuerierCommand ( parsed_params . cmd_params ,
parsed_params . option_map , parsed_params . flags ) ;
} else if ( parsed_params . cmd = = CompactorCommand : : Name ( ) ) {
return new CompactorCommand ( parsed_params . cmd_params ,
parsed_params . option_map , parsed_params . flags ) ;
} else if ( parsed_params . cmd = = WALDumperCommand : : Name ( ) ) {
return new WALDumperCommand ( parsed_params . cmd_params ,
parsed_params . option_map , parsed_params . flags ) ;
} else if ( parsed_params . cmd = = ReduceDBLevelsCommand : : Name ( ) ) {
return new ReduceDBLevelsCommand ( parsed_params . cmd_params ,
parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = ChangeCompactionStyleCommand : : Name ( ) ) {
return new ChangeCompactionStyleCommand ( parsed_params . cmd_params ,
parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = DBDumperCommand : : Name ( ) ) {
return new DBDumperCommand ( parsed_params . cmd_params ,
parsed_params . option_map , parsed_params . flags ) ;
} else if ( parsed_params . cmd = = DBLoaderCommand : : Name ( ) ) {
return new DBLoaderCommand ( parsed_params . cmd_params ,
parsed_params . option_map , parsed_params . flags ) ;
} else if ( parsed_params . cmd = = ManifestDumpCommand : : Name ( ) ) {
return new ManifestDumpCommand ( parsed_params . cmd_params ,
parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = ListColumnFamiliesCommand : : Name ( ) ) {
return new ListColumnFamiliesCommand ( parsed_params . cmd_params ,
parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = CreateColumnFamilyCommand : : Name ( ) ) {
return new CreateColumnFamilyCommand ( parsed_params . cmd_params ,
parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = DBFileDumperCommand : : Name ( ) ) {
return new DBFileDumperCommand ( parsed_params . cmd_params ,
parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = InternalDumpCommand : : Name ( ) ) {
return new InternalDumpCommand ( parsed_params . cmd_params ,
parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = CheckConsistencyCommand : : Name ( ) ) {
return new CheckConsistencyCommand ( parsed_params . cmd_params ,
parsed_params . option_map ,
parsed_params . flags ) ;
} else if ( parsed_params . cmd = = RepairCommand : : Name ( ) ) {
return new RepairCommand ( parsed_params . cmd_params , parsed_params . option_map ,
parsed_params . flags ) ;
}
return nullptr ;
}