diff options
43 files changed, 332 insertions, 438 deletions
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index ea055109a68..63b9605e4f9 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -82,9 +82,7 @@ #include "mongo/util/net/message_server.h" #include "mongo/util/net/ssl_manager.h" #include "mongo/util/ntservice.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" #include "mongo/util/ramlog.h" #include "mongo/util/stacktrace.h" #include "mongo/util/startup_test.h" @@ -827,8 +825,8 @@ static void startupConfigActions(const std::vector<std::string>& args) { // The "command" option is deprecated. For backward compatibility, still support the "run" // and "dbppath" command. The "run" command is the same as just running mongod, so just // falls through. - if (serverParsedOptions.count("command")) { - vector<string> command = serverParsedOptions["command"].as< vector<string> >(); + if (moe::startupOptionsParsed.count("command")) { + vector<string> command = moe::startupOptionsParsed["command"].as< vector<string> >(); if (command[0].compare("dbpath") == 0) { cout << storageGlobalParams.dbpath << endl; @@ -837,27 +835,27 @@ static void startupConfigActions(const std::vector<std::string>& args) { if (command[0].compare("run") != 0) { cout << "Invalid command: " << command[0] << endl; - printMongodHelp(serverOptions); + printMongodHelp(moe::startupOptions); ::_exit(EXIT_FAILURE); } if (command.size() > 1) { cout << "Too many parameters to 'run' command" << endl; - printMongodHelp(serverOptions); + printMongodHelp(moe::startupOptions); ::_exit(EXIT_FAILURE); } } #ifdef _WIN32 ntservice::configureService(initService, - serverParsedOptions, + moe::startupOptionsParsed, defaultServiceStrings, std::vector<std::string>(), args); #endif // _WIN32 #ifdef __linux__ - if (serverParsedOptions.count("shutdown")){ + if (moe::startupOptionsParsed.count("shutdown")){ bool failed = false; string name = (boost::filesystem::path(storageGlobalParams.dbpath) / "mongod.lock").string(); diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index 5353845040e..b13621ba69c 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -41,10 +41,8 @@ #include "mongo/db/server_options.h" #include "mongo/util/mongoutils/str.h" #include "mongo/util/net/ssl_options.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" #include "mongo/util/version.h" namespace mongo { @@ -414,7 +412,7 @@ namespace mongo { Status handlePreValidationMongodOptions(const moe::Environment& params, const std::vector<std::string>& args) { if (params.count("help")) { - printMongodHelp(serverOptions); + printMongodHelp(moe::startupOptions); ::_exit(EXIT_SUCCESS); } if (params.count("version")) { @@ -777,28 +775,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongodOptions)(InitializerContext* context) { - return addMongodOptions(&serverOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongodOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(serverOptions, context->args(), context->env(), - &serverParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongodOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongodOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongodOptions(serverParsedOptions, context->args()); + Status ret = handlePreValidationMongodOptions(moe::startupOptionsParsed, context->args()); if (!ret.isOK()) { return ret; } - ret = serverParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -811,7 +796,7 @@ namespace mongo { // getGlobalAuthorizationManager(). ("EndStartupOptionStorage")) (InitializerContext* context) { - return storeMongodOptions(serverParsedOptions, context->args()); + return storeMongodOptions(moe::startupOptionsParsed, context->args()); } } // namespace mongo diff --git a/src/mongo/db/server_options.cpp b/src/mongo/db/server_options.cpp index 2b8ecc86fa0..c2b38117dcb 100644 --- a/src/mongo/db/server_options.cpp +++ b/src/mongo/db/server_options.cpp @@ -44,17 +44,13 @@ #include "mongo/util/mongoutils/str.h" #include "mongo/util/net/listen.h" // For DEFAULT_MAX_CONN #include "mongo/util/net/ssl_options.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" +#include "mongo/util/options_parser/startup_options.h" namespace mongo { typedef moe::OptionDescription OD; typedef moe::PositionalOptionDescription POD; - moe::OptionSection serverOptions("Allowed options"); - moe::Environment serverParsedOptions; - ServerGlobalParams serverGlobalParams; Status addGeneralServerOptions(moe::OptionSection* options) { diff --git a/src/mongo/db/server_options.h b/src/mongo/db/server_options.h index 753ea8ffb77..899c2c63b47 100644 --- a/src/mongo/db/server_options.h +++ b/src/mongo/db/server_options.h @@ -38,13 +38,11 @@ namespace mongo { namespace optionenvironment { class OptionSection; + class Environment; } // namespace optionenvironment namespace moe = mongo::optionenvironment; - extern moe::OptionSection serverOptions; - extern moe::Environment serverParsedOptions; - struct ServerGlobalParams { ServerGlobalParams() : diff --git a/src/mongo/dbtests/framework_options.cpp b/src/mongo/dbtests/framework_options.cpp index 5f213ce049c..e9f864453c3 100644 --- a/src/mongo/dbtests/framework_options.cpp +++ b/src/mongo/dbtests/framework_options.cpp @@ -25,17 +25,12 @@ #include "mongo/db/storage_options.h" #include "mongo/dbtests/dbtests.h" #include "mongo/unittest/unittest.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" #include "mongo/util/password.h" namespace mongo { - moe::OptionSection frameworkOptions("options"); - moe::Environment frameworkParsedOptions; FrameworkGlobalParams frameworkGlobalParams; Status addTestFrameworkOptions(moe::OptionSection* options) { @@ -137,7 +132,7 @@ namespace mongo { Status handlePreValidationTestFrameworkOptions(const moe::Environment& params, const std::vector<std::string>& args) { if (params.count("help")) { - std::cout << getTestFrameworkHelp(args[0], frameworkOptions) << std::endl; + std::cout << getTestFrameworkHelp(args[0], moe::startupOptions) << std::endl; ::_exit(EXIT_SUCCESS); } @@ -202,7 +197,7 @@ namespace mongo { if (!boost::filesystem::is_directory(p)) { std::cerr << "ERROR: path \"" << p.string() << "\" is not a directory" << std::endl; - std::cerr << getTestFrameworkHelp(args[0], frameworkOptions) << std::endl; + std::cerr << getTestFrameworkHelp(args[0], moe::startupOptions) << std::endl; ::_exit(EXIT_BADOPTIONS); } boost::filesystem::directory_iterator end_iter; @@ -268,29 +263,16 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(FrameworkOptions)(InitializerContext* context) { - return addTestFrameworkOptions(&frameworkOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(FrameworkOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(frameworkOptions, context->args(), context->env(), - &frameworkParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addTestFrameworkOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(FrameworkOptions)(InitializerContext* context) { - Status ret = handlePreValidationTestFrameworkOptions(frameworkParsedOptions, + Status ret = handlePreValidationTestFrameworkOptions(moe::startupOptionsParsed, context->args()); if (!ret.isOK()) { return ret; } - ret = frameworkParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -298,6 +280,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(FrameworkOptions)(InitializerContext* context) { - return storeTestFrameworkOptions(frameworkParsedOptions, context->args()); + return storeTestFrameworkOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/dbtests/framework_options.h b/src/mongo/dbtests/framework_options.h index 2bc5df57bc6..7ee10eb456a 100644 --- a/src/mongo/dbtests/framework_options.h +++ b/src/mongo/dbtests/framework_options.h @@ -30,9 +30,6 @@ namespace mongo { namespace moe = mongo::optionenvironment; - extern moe::OptionSection frameworkOptions; - extern moe::Environment frameworkParsedOptions; - struct FrameworkGlobalParams { unsigned perfHist; unsigned long long seed; diff --git a/src/mongo/s/mongos_options.cpp b/src/mongo/s/mongos_options.cpp index 4e337aa435c..6f29e4796e1 100644 --- a/src/mongo/s/mongos_options.cpp +++ b/src/mongo/s/mongos_options.cpp @@ -25,10 +25,8 @@ #include "mongo/s/chunk.h" #include "mongo/s/version_mongos.h" #include "mongo/util/net/ssl_options.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" #include "mongo/util/startup_test.h" #include "mongo/util/stringutils.h" @@ -137,7 +135,7 @@ namespace mongo { Status handlePreValidationMongosOptions(const moe::Environment& params, const std::vector<std::string>& args) { if (params.count("help")) { - printMongosHelp(serverOptions); + printMongosHelp(moe::startupOptions); ::_exit(EXIT_SUCCESS); } if (params.count("version")) { @@ -238,28 +236,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongosOptions)(InitializerContext* context) { - return addMongosOptions(&serverOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongosOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(serverOptions, context->args(), context->env(), - &serverParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongosOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongosOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongosOptions(serverParsedOptions, context->args()); + Status ret = handlePreValidationMongosOptions(moe::startupOptionsParsed, context->args()); if (!ret.isOK()) { return ret; } - ret = serverParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -272,7 +257,7 @@ namespace mongo { // getGlobalAuthorizationManager(). ("EndStartupOptionStorage")) (InitializerContext* context) { - return storeMongosOptions(serverParsedOptions, context->args()); + return storeMongosOptions(moe::startupOptionsParsed, context->args()); } } // namespace mongo diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp index 77110bc91b6..e2b348e252a 100644 --- a/src/mongo/shell/shell_options.cpp +++ b/src/mongo/shell/shell_options.cpp @@ -24,17 +24,12 @@ #include "mongo/shell/shell_utils.h" #include "mongo/util/net/sock.h" #include "mongo/util/net/ssl_options.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" #include "mongo/util/version.h" namespace mongo { - moe::OptionSection mongoShellOptions("options"); - moe::Environment mongoShellParsedOptions; ShellGlobalParams shellGlobalParams; Status addMongoShellOptions(moe::OptionSection* options) { @@ -170,27 +165,27 @@ namespace mongo { Status handlePreValidationMongoShellOptions(const moe::Environment& params, const std::vector<std::string>& args) { - if ( mongoShellParsedOptions.count( "help" ) ) { - std::cout << getMongoShellHelp(args[0], mongoShellOptions) << std::endl; + if (params.count("help")) { + std::cout << getMongoShellHelp(args[0], moe::startupOptions) << std::endl; ::_exit(EXIT_CLEAN); } - if ( mongoShellParsedOptions.count( "version" ) ) { + if (params.count("version")) { cout << "MongoDB shell version: " << mongo::versionString << endl; ::_exit(EXIT_CLEAN); } - if (mongoShellParsedOptions.count("quiet")) { + if (params.count("quiet")) { mongo::serverGlobalParams.quiet = true; } #ifdef MONGO_SSL - Status ret = storeSSLClientOptions(mongoShellParsedOptions); + Status ret = storeSSLClientOptions(params); if (!ret.isOK()) { return ret; } #endif - if (mongoShellParsedOptions.count("ipv6")) { + if (params.count("ipv6")) { mongo::enableIPv6(); } - if (mongoShellParsedOptions.count("verbose")) { + if (params.count("verbose")) { logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(1)); } @@ -199,53 +194,53 @@ namespace mongo { Status storeMongoShellOptions(const moe::Environment& params, const std::vector<std::string>& args) { - if (mongoShellParsedOptions.count("port")) { - shellGlobalParams.port = mongoShellParsedOptions["port"].as<string>(); + if (params.count("port")) { + shellGlobalParams.port = params["port"].as<string>(); } - if (mongoShellParsedOptions.count("host")) { - shellGlobalParams.dbhost = mongoShellParsedOptions["host"].as<string>(); + if (params.count("host")) { + shellGlobalParams.dbhost = params["host"].as<string>(); } - if (mongoShellParsedOptions.count("eval")) { - shellGlobalParams.script = mongoShellParsedOptions["eval"].as<string>(); + if (params.count("eval")) { + shellGlobalParams.script = params["eval"].as<string>(); } - if (mongoShellParsedOptions.count("username")) { - shellGlobalParams.username = mongoShellParsedOptions["username"].as<string>(); + if (params.count("username")) { + shellGlobalParams.username = params["username"].as<string>(); } - if (mongoShellParsedOptions.count("password")) { + if (params.count("password")) { shellGlobalParams.usingPassword = true; - shellGlobalParams.password = mongoShellParsedOptions["password"].as<string>(); + shellGlobalParams.password = params["password"].as<string>(); } - if (mongoShellParsedOptions.count("authenticationDatabase")) { + if (params.count("authenticationDatabase")) { shellGlobalParams.authenticationDatabase = - mongoShellParsedOptions["authenticationDatabase"].as<string>(); + params["authenticationDatabase"].as<string>(); } - if (mongoShellParsedOptions.count("authenticationMechanism")) { + if (params.count("authenticationMechanism")) { shellGlobalParams.authenticationMechanism = - mongoShellParsedOptions["authenticationMechanism"].as<string>(); + params["authenticationMechanism"].as<string>(); } - if ( mongoShellParsedOptions.count( "shell" ) ) { + if (params.count("shell")) { shellGlobalParams.runShell = true; } - if ( mongoShellParsedOptions.count( "nodb" ) ) { + if (params.count("nodb")) { shellGlobalParams.nodb = true; } - if ( mongoShellParsedOptions.count( "norc" ) ) { + if (params.count("norc")) { shellGlobalParams.norc = true; } - if ( mongoShellParsedOptions.count( "files" ) ) { - shellGlobalParams.files = mongoShellParsedOptions["files"].as< vector<string> >(); + if (params.count("files")) { + shellGlobalParams.files = params["files"].as< vector<string> >(); } - if ( mongoShellParsedOptions.count( "nokillop" ) ) { + if (params.count("nokillop")) { mongo::shell_utils::_nokillop = true; } - if ( mongoShellParsedOptions.count( "autokillop" ) ) { + if (params.count("autokillop")) { shellGlobalParams.autoKillOp = true; } @@ -256,8 +251,8 @@ namespace mongo { * only if one of these conditions is met: * - it contains no '.' after the last appearance of '\' or '/' * - it doesn't end in '.js' and it doesn't specify a path to an existing file */ - if ( mongoShellParsedOptions.count( "dbaddress" ) ) { - string dbaddress = mongoShellParsedOptions["dbaddress"].as<string>(); + if (params.count("dbaddress")) { + string dbaddress = params["dbaddress"].as<string>(); if (shellGlobalParams.nodb) { shellGlobalParams.files.insert( shellGlobalParams.files.begin(), dbaddress ); } @@ -276,7 +271,7 @@ namespace mongo { if ( shellGlobalParams.url == "*" ) { std::cerr << "ERROR: " << "\"*\" is an invalid db address" << std::endl; - std::cerr << getMongoShellHelp(args[0], mongoShellOptions) << std::endl; + std::cerr << getMongoShellHelp(args[0], moe::startupOptions) << std::endl; ::_exit(EXIT_BADOPTIONS); } @@ -284,28 +279,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoShellOptions)(InitializerContext* context) { - return addMongoShellOptions(&mongoShellOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongoShellOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(mongoShellOptions, context->args(), context->env(), - &mongoShellParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongoShellOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongoShellOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoShellOptions(mongoShellParsedOptions, context->args()); + Status ret = handlePreValidationMongoShellOptions(moe::startupOptionsParsed, context->args()); if (!ret.isOK()) { return ret; } - ret = mongoShellParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -313,6 +295,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoShellOptions)(InitializerContext* context) { - return storeMongoShellOptions(mongoShellParsedOptions, context->args()); + return storeMongoShellOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/shell/shell_options.h b/src/mongo/shell/shell_options.h index ede47c15b79..d48b2226b9c 100644 --- a/src/mongo/shell/shell_options.h +++ b/src/mongo/shell/shell_options.h @@ -30,9 +30,6 @@ namespace mongo { namespace moe = mongo::optionenvironment; - extern moe::OptionSection mongoShellOptions; - extern moe::Environment mongoShellParsedOptions; - struct ShellGlobalParams { std::string url; std::string dbhost; diff --git a/src/mongo/tools/bsondump.cpp b/src/mongo/tools/bsondump.cpp index ea4a9e6ebfe..3b1e74037c9 100644 --- a/src/mongo/tools/bsondump.cpp +++ b/src/mongo/tools/bsondump.cpp @@ -36,7 +36,7 @@ public: BSONDump() : BSONTool() { } virtual void printHelp(ostream& out) { - printBSONDumpHelp(toolsOptions, &out); + printBSONDumpHelp(&out); } virtual int doRun() { @@ -53,7 +53,7 @@ public: boost::filesystem::path root = bsonDumpGlobalParams.file; if ( root == "" ) { - printBSONDumpHelp(toolsOptions, &std::cout); + printBSONDumpHelp(&std::cout); return 1; } diff --git a/src/mongo/tools/bsondump_options.cpp b/src/mongo/tools/bsondump_options.cpp index 6bda2030daa..f75d0dd96e2 100644 --- a/src/mongo/tools/bsondump_options.cpp +++ b/src/mongo/tools/bsondump_options.cpp @@ -17,11 +17,8 @@ #include "mongo/tools/bsondump_options.h" #include "mongo/base/status.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" namespace mongo { @@ -55,16 +52,16 @@ namespace mongo { return Status::OK(); } - void printBSONDumpHelp(const moe::OptionSection options, std::ostream* out) { + void printBSONDumpHelp(std::ostream* out) { *out << "Display BSON objects in a data file.\n" << std::endl; *out << "usage: bsondump [options] <bson filename>" << std::endl; - *out << options.helpString(); + *out << moe::startupOptions.helpString(); *out << std::flush; } Status handlePreValidationBSONDumpOptions(const moe::Environment& params) { - if (toolsParsedOptions.count("help")) { - printBSONDumpHelp(toolsOptions, &std::cout); + if (params.count("help")) { + printBSONDumpHelp(&std::cout); ::_exit(0); } return Status::OK(); @@ -89,7 +86,7 @@ namespace mongo { bsonDumpGlobalParams.file = getParam("file"); // Make the default db "" if it was not explicitly set - if (!toolsParsedOptions.count("db")) { + if (!params.count("db")) { toolGlobalParams.db = ""; } @@ -97,28 +94,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(BSONDumpOptions)(InitializerContext* context) { - return addBSONDumpOptions(&toolsOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(BSONDumpOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(toolsOptions, context->args(), context->env(), - &toolsParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addBSONDumpOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(BSONDumpOptions)(InitializerContext* context) { - Status ret = handlePreValidationBSONDumpOptions(toolsParsedOptions); + Status ret = handlePreValidationBSONDumpOptions(moe::startupOptionsParsed); if (!ret.isOK()) { return ret; } - ret = toolsParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -126,6 +110,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(BSONDumpOptions)(InitializerContext* context) { - return storeBSONDumpOptions(toolsParsedOptions, context->args()); + return storeBSONDumpOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/tools/bsondump_options.h b/src/mongo/tools/bsondump_options.h index b6683c13f80..0afddd57658 100644 --- a/src/mongo/tools/bsondump_options.h +++ b/src/mongo/tools/bsondump_options.h @@ -34,7 +34,7 @@ namespace mongo { Status addBSONDumpOptions(moe::OptionSection* options); - void printBSONDumpHelp(const moe::OptionSection options, std::ostream* out); + void printBSONDumpHelp(std::ostream* out); Status handlePreValidationBSONDumpOptions(const moe::Environment& params); diff --git a/src/mongo/tools/dump.cpp b/src/mongo/tools/dump.cpp index 1a9673d49a3..a58640a57c1 100644 --- a/src/mongo/tools/dump.cpp +++ b/src/mongo/tools/dump.cpp @@ -52,7 +52,7 @@ public: } virtual void printHelp(ostream& out) { - printMongoDumpHelp(toolsOptions, &out); + printMongoDumpHelp(&out); } // This is a functor that writes a BSONObj to a file diff --git a/src/mongo/tools/export.cpp b/src/mongo/tools/export.cpp index fd6db1e3cd2..f135d9853f3 100644 --- a/src/mongo/tools/export.cpp +++ b/src/mongo/tools/export.cpp @@ -45,7 +45,7 @@ public: } virtual void printHelp( ostream & out ) { - printMongoExportHelp(toolsOptions, &out); + printMongoExportHelp(&out); } // Turn every double quote character into two double quote characters diff --git a/src/mongo/tools/files.cpp b/src/mongo/tools/files.cpp index b1075fb2512..0c786d191d8 100644 --- a/src/mongo/tools/files.cpp +++ b/src/mongo/tools/files.cpp @@ -33,7 +33,7 @@ public: Files() : Tool() { } virtual void printHelp( ostream & out ) { - printMongoFilesHelp(toolsOptions, &out); + printMongoFilesHelp(&out); } void display( GridFS * grid , BSONObj obj ) { diff --git a/src/mongo/tools/import.cpp b/src/mongo/tools/import.cpp index c2015cf3252..536f3f81afc 100644 --- a/src/mongo/tools/import.cpp +++ b/src/mongo/tools/import.cpp @@ -273,7 +273,7 @@ public: } virtual void printHelp( ostream & out ) { - printMongoImportHelp(toolsOptions, &out); + printMongoImportHelp(&out); } unsigned long long lastErrorFailures; diff --git a/src/mongo/tools/mongodump_options.cpp b/src/mongo/tools/mongodump_options.cpp index a8ad0daf82e..c132079acb9 100644 --- a/src/mongo/tools/mongodump_options.cpp +++ b/src/mongo/tools/mongodump_options.cpp @@ -18,11 +18,8 @@ #include "mongo/base/status.h" #include "mongo/util/log.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" namespace mongo { @@ -81,15 +78,15 @@ namespace mongo { return Status::OK(); } - void printMongoDumpHelp(const moe::OptionSection options, std::ostream* out) { + void printMongoDumpHelp(std::ostream* out) { *out << "Export MongoDB data to BSON files.\n" << std::endl; - *out << options.helpString(); + *out << moe::startupOptions.helpString(); *out << std::flush; } Status handlePreValidationMongoDumpOptions(const moe::Environment& params) { - if (toolsParsedOptions.count("help")) { - printMongoDumpHelp(toolsOptions, &std::cout); + if (params.count("help")) { + printMongoDumpHelp(&std::cout); ::_exit(0); } return Status::OK(); @@ -129,7 +126,7 @@ namespace mongo { } // Make the default db "" if it was not explicitly set - if (!toolsParsedOptions.count("db")) { + if (!params.count("db")) { toolGlobalParams.db = ""; } @@ -137,28 +134,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoDumpOptions)(InitializerContext* context) { - return addMongoDumpOptions(&toolsOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongoDumpOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(toolsOptions, context->args(), context->env(), - &toolsParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongoDumpOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongoDumpOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoDumpOptions(toolsParsedOptions); + Status ret = handlePreValidationMongoDumpOptions(moe::startupOptionsParsed); if (!ret.isOK()) { return ret; } - ret = toolsParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -166,6 +150,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoDumpOptions)(InitializerContext* context) { - return storeMongoDumpOptions(toolsParsedOptions, context->args()); + return storeMongoDumpOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/tools/mongodump_options.h b/src/mongo/tools/mongodump_options.h index fc228af2b89..9f051809244 100644 --- a/src/mongo/tools/mongodump_options.h +++ b/src/mongo/tools/mongodump_options.h @@ -37,7 +37,7 @@ namespace mongo { Status addMongoDumpOptions(moe::OptionSection* options); - void printMongoDumpHelp(const moe::OptionSection options, std::ostream* out); + void printMongoDumpHelp(std::ostream* out); Status handlePreValidationMongoDumpOptions(const moe::Environment& params); diff --git a/src/mongo/tools/mongoexport_options.cpp b/src/mongo/tools/mongoexport_options.cpp index f4090d2a733..375e2ff624b 100644 --- a/src/mongo/tools/mongoexport_options.cpp +++ b/src/mongo/tools/mongoexport_options.cpp @@ -17,11 +17,8 @@ #include "mongo/tools/mongoexport_options.h" #include "mongo/base/status.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" namespace mongo { @@ -102,15 +99,15 @@ namespace mongo { return Status::OK(); } - void printMongoExportHelp(const moe::OptionSection options, std::ostream* out) { + void printMongoExportHelp(std::ostream* out) { *out << "Export MongoDB data to CSV, TSV or JSON files.\n" << std::endl; - *out << options.helpString(); + *out << moe::startupOptions.helpString(); *out << std::flush; } Status handlePreValidationMongoExportOptions(const moe::Environment& params) { - if (toolsParsedOptions.count("help")) { - printMongoExportHelp(toolsOptions, &std::cout); + if (params.count("help")) { + printMongoExportHelp(&std::cout); ::_exit(0); } return Status::OK(); @@ -137,7 +134,7 @@ namespace mongo { if (!hasParam("query") && !hasParam("dbpath") && !hasParam("forceTableScan")) { mongoExportGlobalParams.snapShotQuery = true; } - mongoExportGlobalParams.slaveOk = toolsParsedOptions["slaveOk"].as<bool>(); + mongoExportGlobalParams.slaveOk = params["slaveOk"].as<bool>(); mongoExportGlobalParams.limit = getParam("limit", 0); mongoExportGlobalParams.skip = getParam("skip", 0); @@ -145,28 +142,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoExportOptions)(InitializerContext* context) { - return addMongoExportOptions(&toolsOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongoExportOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(toolsOptions, context->args(), context->env(), - &toolsParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongoExportOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongoExportOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoExportOptions(toolsParsedOptions); + Status ret = handlePreValidationMongoExportOptions(moe::startupOptionsParsed); if (!ret.isOK()) { return ret; } - ret = toolsParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -174,6 +158,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoExportOptions)(InitializerContext* context) { - return storeMongoExportOptions(toolsParsedOptions, context->args()); + return storeMongoExportOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/tools/mongoexport_options.h b/src/mongo/tools/mongoexport_options.h index b6a823c90f3..86da8c3de11 100644 --- a/src/mongo/tools/mongoexport_options.h +++ b/src/mongo/tools/mongoexport_options.h @@ -41,7 +41,7 @@ namespace mongo { Status addMongoExportOptions(moe::OptionSection* options); - void printMongoExportHelp(const moe::OptionSection options, std::ostream* out); + void printMongoExportHelp(std::ostream* out); Status handlePreValidationMongoExportOptions(const moe::Environment& params); diff --git a/src/mongo/tools/mongofiles_options.cpp b/src/mongo/tools/mongofiles_options.cpp index c4c70ac1ca2..814106e7467 100644 --- a/src/mongo/tools/mongofiles_options.cpp +++ b/src/mongo/tools/mongofiles_options.cpp @@ -17,11 +17,8 @@ #include "mongo/tools/mongofiles_options.h" #include "mongo/base/status.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" namespace mongo { @@ -80,7 +77,7 @@ namespace mongo { return Status::OK(); } - void printMongoFilesHelp(const moe::OptionSection options, std::ostream* out) { + void printMongoFilesHelp(std::ostream* out) { *out << "Browse and modify a GridFS filesystem.\n" << std::endl; *out << "usage: mongofiles [options] command [gridfs filename]" << std::endl; *out << "command:" << std::endl; @@ -92,13 +89,13 @@ namespace mongo { *out << " put - add a file with filename 'gridfs filename'" << std::endl; *out << " get - get a file with filename 'gridfs filename'" << std::endl; *out << " delete - delete all files with filename 'gridfs filename'" << std::endl; - *out << options.helpString(); + *out << moe::startupOptions.helpString(); *out << std::flush; } Status handlePreValidationMongoFilesOptions(const moe::Environment& params) { - if (toolsParsedOptions.count("help")) { - printMongoFilesHelp(toolsOptions, &std::cout); + if (params.count("help")) { + printMongoFilesHelp(&std::cout); ::_exit(0); } return Status::OK(); @@ -121,28 +118,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoFilesOptions)(InitializerContext* context) { - return addMongoFilesOptions(&toolsOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongoFilesOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(toolsOptions, context->args(), context->env(), - &toolsParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongoFilesOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongoFilesOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoFilesOptions(toolsParsedOptions); + Status ret = handlePreValidationMongoFilesOptions(moe::startupOptionsParsed); if (!ret.isOK()) { return ret; } - ret = toolsParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -150,6 +134,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoFilesOptions)(InitializerContext* context) { - return storeMongoFilesOptions(toolsParsedOptions, context->args()); + return storeMongoFilesOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/tools/mongofiles_options.h b/src/mongo/tools/mongofiles_options.h index 31cbd55e29d..3dd046a40de 100644 --- a/src/mongo/tools/mongofiles_options.h +++ b/src/mongo/tools/mongofiles_options.h @@ -37,7 +37,7 @@ namespace mongo { Status addMongoFilesOptions(moe::OptionSection* options); - void printMongoFilesHelp(const moe::OptionSection options, std::ostream* out); + void printMongoFilesHelp(std::ostream* out); Status handlePreValidationMongoFilesOptions(const moe::Environment& params); diff --git a/src/mongo/tools/mongoimport_options.cpp b/src/mongo/tools/mongoimport_options.cpp index 549a02e58b4..0c6de3dbf1f 100644 --- a/src/mongo/tools/mongoimport_options.cpp +++ b/src/mongo/tools/mongoimport_options.cpp @@ -17,11 +17,8 @@ #include "mongo/tools/mongoimport_options.h" #include "mongo/base/status.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" #include "mongo/util/text.h" namespace mongo { @@ -118,18 +115,18 @@ namespace mongo { return Status::OK(); } - void printMongoImportHelp(const moe::OptionSection options, std::ostream* out) { + void printMongoImportHelp(std::ostream* out) { *out << "Import CSV, TSV or JSON data into MongoDB.\n" << std::endl; *out << "When importing JSON documents, each document must be a separate line of the input file.\n"; *out << "\nExample:\n"; *out << " mongoimport --host myhost --db my_cms --collection docs < mydocfile.json\n" << std::endl; - *out << options.helpString(); + *out << moe::startupOptions.helpString(); *out << std::flush; } Status handlePreValidationMongoImportOptions(const moe::Environment& params) { - if (toolsParsedOptions.count("help")) { - printMongoImportHelp(toolsOptions, &std::cout); + if (params.count("help")) { + printMongoImportHelp(&std::cout); ::_exit(0); } return Status::OK(); @@ -176,28 +173,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoImportOptions)(InitializerContext* context) { - return addMongoImportOptions(&toolsOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongoImportOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(toolsOptions, context->args(), context->env(), - &toolsParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongoImportOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongoImportOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoImportOptions(toolsParsedOptions); + Status ret = handlePreValidationMongoImportOptions(moe::startupOptionsParsed); if (!ret.isOK()) { return ret; } - ret = toolsParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -205,6 +189,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoImportOptions)(InitializerContext* context) { - return storeMongoImportOptions(toolsParsedOptions, context->args()); + return storeMongoImportOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/tools/mongoimport_options.h b/src/mongo/tools/mongoimport_options.h index 6b4af4d91a7..53f378a3a31 100644 --- a/src/mongo/tools/mongoimport_options.h +++ b/src/mongo/tools/mongoimport_options.h @@ -42,7 +42,7 @@ namespace mongo { Status addMongoImportOptions(moe::OptionSection* options); - void printMongoImportHelp(const moe::OptionSection options, std::ostream* out); + void printMongoImportHelp(std::ostream* out); Status handlePreValidationMongoImportOptions(const moe::Environment& params); diff --git a/src/mongo/tools/mongooplog_options.cpp b/src/mongo/tools/mongooplog_options.cpp index d1e7a7edda8..cd7d27d5cc7 100644 --- a/src/mongo/tools/mongooplog_options.cpp +++ b/src/mongo/tools/mongooplog_options.cpp @@ -18,11 +18,8 @@ #include "mongo/base/status.h" #include "mongo/util/log.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" namespace mongo { @@ -70,15 +67,15 @@ namespace mongo { return Status::OK(); } - void printMongoOplogHelp(const moe::OptionSection options, std::ostream* out) { + void printMongoOplogHelp(std::ostream* out) { *out << "Pull and replay a remote MongoDB oplog.\n" << std::endl; - *out << options.helpString(); + *out << moe::startupOptions.helpString(); *out << std::flush; } Status handlePreValidationMongoOplogOptions(const moe::Environment& params) { - if (toolsParsedOptions.count("help")) { - printMongoOplogHelp(toolsOptions, &std::cout); + if (params.count("help")) { + printMongoOplogHelp(&std::cout); ::_exit(0); } return Status::OK(); @@ -106,28 +103,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoOplogOptions)(InitializerContext* context) { - return addMongoOplogOptions(&toolsOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongoOplogOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(toolsOptions, context->args(), context->env(), - &toolsParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongoOplogOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongoOplogOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoOplogOptions(toolsParsedOptions); + Status ret = handlePreValidationMongoOplogOptions(moe::startupOptionsParsed); if (!ret.isOK()) { return ret; } - ret = toolsParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -135,6 +119,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoOplogOptions)(InitializerContext* context) { - return storeMongoOplogOptions(toolsParsedOptions, context->args()); + return storeMongoOplogOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/tools/mongooplog_options.h b/src/mongo/tools/mongooplog_options.h index 8dca17e72a2..e3c25ee236b 100644 --- a/src/mongo/tools/mongooplog_options.h +++ b/src/mongo/tools/mongooplog_options.h @@ -35,7 +35,7 @@ namespace mongo { Status addMongoOplogOptions(moe::OptionSection* options); - void printMongoOplogHelp(const moe::OptionSection options, std::ostream* out); + void printMongoOplogHelp(std::ostream* out); Status handlePreValidationMongoOplogOptions(const moe::Environment& params); diff --git a/src/mongo/tools/mongorestore_options.cpp b/src/mongo/tools/mongorestore_options.cpp index e51e3f974be..c925fc4c24c 100644 --- a/src/mongo/tools/mongorestore_options.cpp +++ b/src/mongo/tools/mongorestore_options.cpp @@ -17,11 +17,8 @@ #include "mongo/tools/mongorestore_options.h" #include "mongo/base/status.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" namespace mongo { @@ -114,17 +111,17 @@ namespace mongo { return Status::OK(); } - void printMongoRestoreHelp(const moe::OptionSection options, std::ostream* out) { + void printMongoRestoreHelp(std::ostream* out) { *out << "Import BSON files into MongoDB.\n" << std::endl; *out << "usage: mongorestore [options] [directory or filename to restore from]" << std::endl; - *out << options.helpString(); + *out << moe::startupOptions.helpString(); *out << std::flush; } Status handlePreValidationMongoRestoreOptions(const moe::Environment& params) { - if (toolsParsedOptions.count("help")) { - printMongoRestoreHelp(toolsOptions, &std::cout); + if (params.count("help")) { + printMongoRestoreHelp(&std::cout); ::_exit(0); } return Status::OK(); @@ -152,7 +149,7 @@ namespace mongo { mongoRestoreGlobalParams.oplogLimit = getParam("oplogLimit", ""); // Make the default db "" if it was not explicitly set - if (!toolsParsedOptions.count("db")) { + if (!params.count("db")) { toolGlobalParams.db = ""; } @@ -160,28 +157,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoRestoreOptions)(InitializerContext* context) { - return addMongoRestoreOptions(&toolsOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongoRestoreOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(toolsOptions, context->args(), context->env(), - &toolsParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongoRestoreOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongoRestoreOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoRestoreOptions(toolsParsedOptions); + Status ret = handlePreValidationMongoRestoreOptions(moe::startupOptionsParsed); if (!ret.isOK()) { return ret; } - ret = toolsParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -189,6 +173,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoRestoreOptions)(InitializerContext* context) { - return storeMongoRestoreOptions(toolsParsedOptions, context->args()); + return storeMongoRestoreOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/tools/mongorestore_options.h b/src/mongo/tools/mongorestore_options.h index 50fdbbf63cf..692bdf0b343 100644 --- a/src/mongo/tools/mongorestore_options.h +++ b/src/mongo/tools/mongorestore_options.h @@ -40,7 +40,7 @@ namespace mongo { Status addMongoRestoreOptions(moe::OptionSection* options); - void printMongoRestoreHelp(const moe::OptionSection options, std::ostream* out); + void printMongoRestoreHelp(std::ostream* out); Status handlePreValidationMongoRestoreOptions(const moe::Environment& params); diff --git a/src/mongo/tools/mongostat_options.cpp b/src/mongo/tools/mongostat_options.cpp index 1d9cd4e4eae..69b3118338c 100644 --- a/src/mongo/tools/mongostat_options.cpp +++ b/src/mongo/tools/mongostat_options.cpp @@ -17,11 +17,8 @@ #include "mongo/tools/mongostat_options.h" #include "mongo/base/status.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" namespace mongo { @@ -76,11 +73,11 @@ namespace mongo { return Status::OK(); } - void printMongoStatHelp(const moe::OptionSection options, std::ostream* out) { + void printMongoStatHelp(std::ostream* out) { *out << "View live MongoDB performance statistics.\n" << std::endl; *out << "usage: mongostat [options] [sleep time]" << std::endl; *out << "sleep time: time to wait (in seconds) between calls" << std::endl; - *out << options.helpString(); + *out << moe::startupOptions.helpString(); *out << "\n"; *out << " Fields\n"; *out << " inserts \t- # of inserts per second (* means replicated op)\n"; @@ -113,8 +110,8 @@ namespace mongo { } Status handlePreValidationMongoStatOptions(const moe::Environment& params) { - if (toolsParsedOptions.count("help")) { - printMongoStatHelp(toolsOptions, &std::cout); + if (params.count("help")) { + printMongoStatHelp(&std::cout); ::_exit(0); } return Status::OK(); @@ -148,12 +145,12 @@ namespace mongo { mongoStatGlobalParams.allFields = hasParam("all"); // Make the default db "admin" if it was not explicitly set - if (!toolsParsedOptions.count("db")) { + if (!params.count("db")) { toolGlobalParams.db = "admin"; } // Make the default db "admin" if it was not explicitly set - if (!toolsParsedOptions.count("db")) { + if (!params.count("db")) { toolGlobalParams.db = "admin"; } @@ -173,28 +170,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoStatOptions)(InitializerContext* context) { - return addMongoStatOptions(&toolsOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongoStatOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(toolsOptions, context->args(), context->env(), - &toolsParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongoStatOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongoStatOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoStatOptions(toolsParsedOptions); + Status ret = handlePreValidationMongoStatOptions(moe::startupOptionsParsed); if (!ret.isOK()) { return ret; } - ret = toolsParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -202,6 +186,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoStatOptions)(InitializerContext* context) { - return storeMongoStatOptions(toolsParsedOptions, context->args()); + return storeMongoStatOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/tools/mongostat_options.h b/src/mongo/tools/mongostat_options.h index 9dfe0f38240..8eb3f47c925 100644 --- a/src/mongo/tools/mongostat_options.h +++ b/src/mongo/tools/mongostat_options.h @@ -40,7 +40,7 @@ namespace mongo { Status addMongoStatOptions(moe::OptionSection* options); - void printMongoStatHelp(const moe::OptionSection options, std::ostream* out); + void printMongoStatHelp(std::ostream* out); Status handlePreValidationMongoStatOptions(const moe::Environment& params); diff --git a/src/mongo/tools/mongotop_options.cpp b/src/mongo/tools/mongotop_options.cpp index 7fe574748e1..2dde99c2565 100644 --- a/src/mongo/tools/mongotop_options.cpp +++ b/src/mongo/tools/mongotop_options.cpp @@ -17,11 +17,8 @@ #include "mongo/tools/mongotop_options.h" #include "mongo/base/status.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" -#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" namespace mongo { @@ -55,15 +52,15 @@ namespace mongo { return Status::OK(); } - void printMongoTopHelp(const moe::OptionSection options, std::ostream* out) { + void printMongoTopHelp(std::ostream* out) { *out << "View live MongoDB collection statistics.\n" << std::endl; - *out << options.helpString(); + *out << moe::startupOptions.helpString(); *out << std::flush; } Status handlePreValidationMongoTopOptions(const moe::Environment& params) { - if (toolsParsedOptions.count("help")) { - printMongoTopHelp(toolsOptions, &std::cout); + if (params.count("help")) { + printMongoTopHelp(&std::cout); ::_exit(0); } return Status::OK(); @@ -80,7 +77,7 @@ namespace mongo { mongoTopGlobalParams.useLocks = hasParam("locks"); // Make the default db "admin" if it was not explicitly set - if (!toolsParsedOptions.count("db")) { + if (!params.count("db")) { toolGlobalParams.db = "admin"; } @@ -88,28 +85,15 @@ namespace mongo { } MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoTopOptions)(InitializerContext* context) { - return addMongoTopOptions(&toolsOptions); - } - - MONGO_STARTUP_OPTIONS_PARSE(MongoTopOptions)(InitializerContext* context) { - moe::OptionsParser parser; - Status ret = parser.run(toolsOptions, context->args(), context->env(), - &toolsParsedOptions); - if (!ret.isOK()) { - std::cerr << ret.reason() << std::endl; - std::cerr << "try '" << context->args()[0] - << " --help' for more information" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); + return addMongoTopOptions(&moe::startupOptions); } MONGO_STARTUP_OPTIONS_VALIDATE(MongoTopOptions)(InitializerContext* context) { - Status ret = handlePreValidationMongoTopOptions(toolsParsedOptions); + Status ret = handlePreValidationMongoTopOptions(moe::startupOptionsParsed); if (!ret.isOK()) { return ret; } - ret = toolsParsedOptions.validate(); + ret = moe::startupOptionsParsed.validate(); if (!ret.isOK()) { return ret; } @@ -117,6 +101,6 @@ namespace mongo { } MONGO_STARTUP_OPTIONS_STORE(MongoTopOptions)(InitializerContext* context) { - return storeMongoTopOptions(toolsParsedOptions, context->args()); + return storeMongoTopOptions(moe::startupOptionsParsed, context->args()); } } diff --git a/src/mongo/tools/mongotop_options.h b/src/mongo/tools/mongotop_options.h index a001f1005d5..7a67c8f033e 100644 --- a/src/mongo/tools/mongotop_options.h +++ b/src/mongo/tools/mongotop_options.h @@ -34,7 +34,7 @@ namespace mongo { Status addMongoTopOptions(moe::OptionSection* options); - void printMongoTopHelp(const moe::OptionSection options, std::ostream* out); + void printMongoTopHelp(std::ostream* out); Status handlePreValidationMongoTopOptions(const moe::Environment& params); diff --git a/src/mongo/tools/oplog.cpp b/src/mongo/tools/oplog.cpp index f30ec02a473..95cba596911 100644 --- a/src/mongo/tools/oplog.cpp +++ b/src/mongo/tools/oplog.cpp @@ -32,7 +32,7 @@ public: OplogTool() : Tool() { } virtual void printHelp( ostream & out ) { - printMongoOplogHelp(toolsOptions, &out); + printMongoOplogHelp(&out); } int run() { diff --git a/src/mongo/tools/restore.cpp b/src/mongo/tools/restore.cpp index 3f467aa579c..b81a947a536 100644 --- a/src/mongo/tools/restore.cpp +++ b/src/mongo/tools/restore.cpp @@ -53,7 +53,7 @@ public: Restore() : BSONTool() { } virtual void printHelp(ostream& out) { - printMongoRestoreHelp(toolsOptions, &out); + printMongoRestoreHelp(&out); } virtual int doRun() { diff --git a/src/mongo/tools/stat.cpp b/src/mongo/tools/stat.cpp index 46e8e406a96..15baf05b831 100644 --- a/src/mongo/tools/stat.cpp +++ b/src/mongo/tools/stat.cpp @@ -42,7 +42,7 @@ namespace mongo { } virtual void printHelp( ostream & out ) { - printMongoStatHelp(toolsOptions, &out); + printMongoStatHelp(&out); } BSONObj stats() { diff --git a/src/mongo/tools/tool_options.cpp b/src/mongo/tools/tool_options.cpp index 4b6fb5dc3ee..d6151cd883a 100644 --- a/src/mongo/tools/tool_options.cpp +++ b/src/mongo/tools/tool_options.cpp @@ -26,17 +26,13 @@ #include "mongo/util/net/sock.h" #include "mongo/util/net/ssl_manager.h" #include "mongo/util/net/ssl_options.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" +#include "mongo/util/options_parser/startup_options.h" #include "mongo/util/password.h" #include "mongo/util/text.h" #include "mongo/util/version.h" namespace mongo { - moe::OptionSection toolsOptions("options"); - moe::Environment toolsParsedOptions; ToolGlobalParams toolGlobalParams; BSONToolGlobalParams bsonToolGlobalParams; @@ -210,19 +206,19 @@ namespace mongo { } std::string getParam(std::string name, std::string def) { - if (toolsParsedOptions.count(name)) { - return toolsParsedOptions[name.c_str()].as<string>(); + if (moe::startupOptionsParsed.count(name)) { + return moe::startupOptionsParsed[name.c_str()].as<string>(); } return def; } int getParam(std::string name, int def) { - if (toolsParsedOptions.count(name)) { - return toolsParsedOptions[name.c_str()].as<int>(); + if (moe::startupOptionsParsed.count(name)) { + return moe::startupOptionsParsed[name.c_str()].as<int>(); } return def; } bool hasParam(std::string name) { - return toolsParsedOptions.count(name); + return moe::startupOptionsParsed.count(name); } void printToolVersionString(std::ostream &out) { @@ -233,7 +229,7 @@ namespace mongo { } Status handlePreValidationGeneralToolOptions(const moe::Environment& params) { - if (toolsParsedOptions.count("version")) { + if (moe::startupOptionsParsed.count("version")) { printToolVersionString(std::cout); ::_exit(0); } @@ -254,22 +250,22 @@ namespace mongo { storageGlobalParams.dur = false; // Set authentication parameters - if ( toolsParsedOptions.count( "authenticationDatabase" ) ) { + if (params.count("authenticationDatabase")) { toolGlobalParams.authenticationDatabase = - toolsParsedOptions["authenticationDatabase"].as<string>(); + params["authenticationDatabase"].as<string>(); } - if ( toolsParsedOptions.count( "authenticationMechanism" ) ) { + if (params.count("authenticationMechanism")) { toolGlobalParams.authenticationMechanism = - toolsParsedOptions["authenticationMechanism"].as<string>(); + params["authenticationMechanism"].as<string>(); } - if (toolsParsedOptions.count("verbose")) { + if (params.count("verbose")) { logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(1)); } for (string s = "vv"; s.length() <= 12; s.append("v")) { - if (toolsParsedOptions.count(s)) { + if (params.count(s)) { logger::globalLogDomain()->setMinimumLoggedSeverity( logger::LogSeverity::Debug(s.length())); } @@ -280,7 +276,7 @@ namespace mongo { } #ifdef MONGO_SSL - if (toolsParsedOptions.count("ssl")) { + if (params.count("ssl")) { sslGlobalParams.sslMode.store(SSLGlobalParams::SSLMode_sslOnly); } #endif @@ -300,48 +296,48 @@ namespace mongo { toolGlobalParams.quiet = false; toolGlobalParams.noconnection = false; - if (toolsParsedOptions.count("db")) - toolGlobalParams.db = toolsParsedOptions["db"].as<string>(); + if (params.count("db")) + toolGlobalParams.db = params["db"].as<string>(); - if (toolsParsedOptions.count("collection")) - toolGlobalParams.coll = toolsParsedOptions["collection"].as<string>(); + if (params.count("collection")) + toolGlobalParams.coll = params["collection"].as<string>(); - if (toolsParsedOptions.count("username")) - toolGlobalParams.username = toolsParsedOptions["username"].as<string>(); + if (params.count("username")) + toolGlobalParams.username = params["username"].as<string>(); - if (toolsParsedOptions.count("password")) { - toolGlobalParams.password = toolsParsedOptions["password"].as<string>(); + if (params.count("password")) { + toolGlobalParams.password = params["password"].as<string>(); if (toolGlobalParams.password.empty()) { toolGlobalParams.password = askPassword(); } } - if (toolsParsedOptions.count("ipv6")) { + if (params.count("ipv6")) { enableIPv6(); } toolGlobalParams.dbpath = getParam("dbpath"); toolGlobalParams.useDirectClient = hasParam("dbpath"); - if (toolGlobalParams.useDirectClient && toolsParsedOptions.count("journal")) { + if (toolGlobalParams.useDirectClient && params.count("journal")) { storageGlobalParams.dur = true; } if (!toolGlobalParams.useDirectClient) { toolGlobalParams.connectionString = "127.0.0.1"; - if (toolsParsedOptions.count("host")) { + if (params.count("host")) { toolGlobalParams.hostSet = true; - toolGlobalParams.host = toolsParsedOptions["host"].as<string>(); - toolGlobalParams.connectionString = toolsParsedOptions["host"].as<string>(); + toolGlobalParams.host = params["host"].as<string>(); + toolGlobalParams.connectionString = params["host"].as<string>(); } - if (toolsParsedOptions.count("port")) { + if (params.count("port")) { toolGlobalParams.portSet = true; - toolGlobalParams.port = toolsParsedOptions["port"].as<string>(); - toolGlobalParams.connectionString += ':' + toolsParsedOptions["port"].as<string>(); + toolGlobalParams.port = params["port"].as<string>(); + toolGlobalParams.connectionString += ':' + params["port"].as<string>(); } } else { - if (toolsParsedOptions.count("directoryperdb")) { + if (params.count("directoryperdb")) { storageGlobalParams.directoryperdb = true; } diff --git a/src/mongo/tools/tool_options.h b/src/mongo/tools/tool_options.h index 465a83a44fc..470960c0b05 100644 --- a/src/mongo/tools/tool_options.h +++ b/src/mongo/tools/tool_options.h @@ -31,9 +31,6 @@ namespace mongo { namespace moe = mongo::optionenvironment; - extern moe::OptionSection toolsOptions; - extern moe::Environment toolsParsedOptions; - struct ToolGlobalParams { ToolGlobalParams() : hostSet(false), portSet(false) { } diff --git a/src/mongo/tools/top.cpp b/src/mongo/tools/top.cpp index 650bf4cd7a9..40fccdf86ab 100644 --- a/src/mongo/tools/top.cpp +++ b/src/mongo/tools/top.cpp @@ -35,7 +35,7 @@ namespace mongo { } virtual void printHelp( ostream & out ) { - printMongoTopHelp(toolsOptions, &out); + printMongoTopHelp(&out); } NamespaceStats getData() { diff --git a/src/mongo/util/net/ssl_options.cpp b/src/mongo/util/net/ssl_options.cpp index 935b3ee9bdd..c72dc0fb129 100644 --- a/src/mongo/util/net/ssl_options.cpp +++ b/src/mongo/util/net/ssl_options.cpp @@ -19,9 +19,7 @@ #include "mongo/base/status.h" #include "mongo/db/server_options.h" -#include "mongo/util/options_parser/environment.h" -#include "mongo/util/options_parser/option_description.h" -#include "mongo/util/options_parser/option_section.h" +#include "mongo/util/options_parser/startup_options.h" namespace mongo { diff --git a/src/mongo/util/net/ssl_options.h b/src/mongo/util/net/ssl_options.h index dce6a9e8444..9bdbc9cd4ca 100644 --- a/src/mongo/util/net/ssl_options.h +++ b/src/mongo/util/net/ssl_options.h @@ -27,8 +27,6 @@ namespace mongo { namespace moe = mongo::optionenvironment; - extern moe::Environment sslParsedOptions; - struct SSLGlobalParams { AtomicInt32 sslMode; // --sslMode - the SSL operation mode, see enum SSLModes bool sslOnNormalPorts; // --sslOnNormalPorts (deprecated) diff --git a/src/mongo/util/options_parser/SConscript b/src/mongo/util/options_parser/SConscript index 69b35809b6c..2390c19d6eb 100644 --- a/src/mongo/util/options_parser/SConscript +++ b/src/mongo/util/options_parser/SConscript @@ -8,6 +8,7 @@ env.StaticLibrary('options_parser', ['environment.cpp', 'option_section.cpp', 'options_parser.cpp', 'startup_option_init.cpp', + 'startup_options.cpp', ], LIBDEPS=['$BUILD_DIR/mongo/bson']) diff --git a/src/mongo/util/options_parser/startup_options.cpp b/src/mongo/util/options_parser/startup_options.cpp new file mode 100644 index 00000000000..9edc42276d9 --- /dev/null +++ b/src/mongo/util/options_parser/startup_options.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2013 10gen Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/util/options_parser/startup_options.h" + +#include "mongo/util/exit_code.h" +#include "mongo/util/options_parser/option_description.h" +#include "mongo/util/options_parser/option_description.h" +#include "mongo/util/options_parser/option_section.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_option_init.h" + +namespace mongo { +namespace optionenvironment { + + OptionSection startupOptions("Options"); + Environment startupOptionsParsed; + +MONGO_STARTUP_OPTIONS_PARSE(StartupOptions)(InitializerContext* context) { + OptionsParser parser; + Status ret = parser.run(startupOptions, context->args(), context->env(), + &startupOptionsParsed); + if (!ret.isOK()) { + std::cerr << ret.reason() << std::endl; + // TODO: Figure out if there's a use case for this help message ever being different + std::cerr << "try '" << context->args()[0] + << " --help' for more information" << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); +} + +} // namespace optionenvironment +} // namespace mongo diff --git a/src/mongo/util/options_parser/startup_options.h b/src/mongo/util/options_parser/startup_options.h new file mode 100644 index 00000000000..926dc46daa6 --- /dev/null +++ b/src/mongo/util/options_parser/startup_options.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2013 10gen Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/util/options_parser/environment.h" +#include "mongo/util/options_parser/option_section.h" + +namespace mongo { +namespace optionenvironment { + + /* + * This structure stores information about all the command line options. The parser will use + * this description when it parses the command line, the INI config file, and the JSON config + * file. See the OptionSection and OptionDescription classes for more details. + * + * Example: + * MONGO_MODULE_STARTUP_OPTIONS_REGISTER(MongodOptions)(InitializerContext* context) { + * return addMongodOptions(&moe::startupOptions); + * ret = startupOptions.addOption(OD("option", "option", moe::String, "description")) + * if (!ret.isOK()) { + * return ret; + * } + * return Status::OK(); + * } + */ + extern OptionSection startupOptions; + + /* + * This structure stores the parsed command line options. After the "defult" group of the + * MONGO_INITIALIZERS, this structure should be fully validated from an option perspective. See + * the Environment, Constraint, and Value classes for more details. + * + * Example: + * if (startupOptionsParsed.count("option")) { + * std::string value; + * ret = startupOptionsParsed.get("option", &value); + * if (!ret.isOK()) { + * return ret; + * } + * } + */ + extern Environment startupOptionsParsed; + +} // namespace optionenvironment +} // namespace mongo |