diff options
author | Shaun Verch <shaun.verch@10gen.com> | 2013-10-12 22:53:52 -0400 |
---|---|---|
committer | Shaun Verch <shaun.verch@10gen.com> | 2013-10-14 10:25:47 -0400 |
commit | a428f58a6fd4f9497b60b10fa749e5cf2eec7b7c (patch) | |
tree | faffac81a243edcef261fa5759f693396bef9d3e /src/mongo/tools/mongobridge_options.cpp | |
parent | 3f2c4c4afd0169a594d766d54f8b0444ecdc8d6a (diff) | |
download | mongo-a428f58a6fd4f9497b60b10fa749e5cf2eec7b7c.tar.gz |
SERVER-8510 Register mongobridge options with new options parser
Diffstat (limited to 'src/mongo/tools/mongobridge_options.cpp')
-rw-r--r-- | src/mongo/tools/mongobridge_options.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/mongo/tools/mongobridge_options.cpp b/src/mongo/tools/mongobridge_options.cpp new file mode 100644 index 00000000000..8ce860d0db5 --- /dev/null +++ b/src/mongo/tools/mongobridge_options.cpp @@ -0,0 +1,117 @@ +/* + * 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/>. + */ + +#include "mongo/tools/mongobridge_options.h" + +#include "mongo/base/status.h" +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + + MongoBridgeGlobalParams mongoBridgeGlobalParams; + + typedef moe::OptionDescription OD; + typedef moe::PositionalOptionDescription POD; + + Status addMongoBridgeOptions(moe::OptionSection* options) { + + Status ret = options->addOption(OD("help", "help", moe::Switch, + "produce help message", true)); + if(!ret.isOK()) { + return ret; + } + + ret = options->addOption(OD("port", "port", moe::Int, "port to listen for mongo messages")); + if(!ret.isOK()) { + return ret; + } + + ret = options->addOption(OD("dest", "dest", moe::String, "uri of remote mongod instance")); + if(!ret.isOK()) { + return ret; + } + + ret = options->addOption(OD("delay", "delay", moe::Int, + "transfer delay in milliseconds (default = 0)", true, moe::Value(0))); + if(!ret.isOK()) { + return ret; + } + + return Status::OK(); + } + + void printMongoBridgeHelp(std::ostream* out) { + *out << "Usage: mongobridge --port <port> --dest <dest> [ --delay <ms> ] [ --help ]" + << std::endl; + *out << moe::startupOptions.helpString(); + *out << std::flush; + } + + Status handlePreValidationMongoBridgeOptions(const moe::Environment& params) { + if (params.count("help")) { + printMongoBridgeHelp(&std::cout); + ::_exit(0); + } + return Status::OK(); + } + + Status storeMongoBridgeOptions(const moe::Environment& params, + const std::vector<std::string>& args) { + + if (!params.count("port")) { + std::cerr << "Missing required option: \"--port\"" << std::endl; + printMongoBridgeHelp(&std::cerr); + ::_exit(0); + } + + if (!params.count("dest")) { + std::cerr << "Missing required option: \"--dest\"" << std::endl; + printMongoBridgeHelp(&std::cerr); + ::_exit(0); + } + + mongoBridgeGlobalParams.port = params["port"].as<int>(); + mongoBridgeGlobalParams.destUri = params["dest"].as<std::string>(); + + if (params.count("delay")) { + mongoBridgeGlobalParams.delay = params["delay"].as<int>(); + } + + return Status::OK(); + } + + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoBridgeOptions)(InitializerContext* context) { + return addMongoBridgeOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(MongoBridgeOptions)(InitializerContext* context) { + Status ret = handlePreValidationMongoBridgeOptions(moe::startupOptionsParsed); + if (!ret.isOK()) { + return ret; + } + ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(MongoBridgeOptions)(InitializerContext* context) { + return storeMongoBridgeOptions(moe::startupOptionsParsed, context->args()); + } +} + |