diff options
author | Shaun Verch <shaun.verch@10gen.com> | 2013-10-21 02:02:26 -0400 |
---|---|---|
committer | Shaun Verch <shaun.verch@10gen.com> | 2013-10-23 19:41:30 -0400 |
commit | 22f5a8622731353890352dbaccdebdc937ae8508 (patch) | |
tree | cdce2b2de98c0d5b23aa67a1548fe9c865f4eb50 /src/mongo/tools | |
parent | 89218f62b7ad5114df7e956bec47b4c1f96f1fed (diff) | |
download | mongo-22f5a8622731353890352dbaccdebdc937ae8508.tar.gz |
SERVER-11144 Create unit tests for registration in all option files
Diffstat (limited to 'src/mongo/tools')
30 files changed, 3847 insertions, 262 deletions
diff --git a/src/mongo/tools/bsondump_options.cpp b/src/mongo/tools/bsondump_options.cpp index 73739f174cf..e2e659dd6bd 100644 --- a/src/mongo/tools/bsondump_options.cpp +++ b/src/mongo/tools/bsondump_options.cpp @@ -17,7 +17,6 @@ #include "mongo/tools/bsondump_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 { @@ -96,29 +95,4 @@ namespace mongo { return Status::OK(); } - MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(BSONDumpOptions)(InitializerContext* context) { - return addBSONDumpOptions(&moe::startupOptions); - } - - MONGO_STARTUP_OPTIONS_VALIDATE(BSONDumpOptions)(InitializerContext* context) { - if (handlePreValidationBSONDumpOptions(moe::startupOptionsParsed)) { - ::_exit(EXIT_SUCCESS); - } - Status ret = moe::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); - } - - MONGO_STARTUP_OPTIONS_STORE(BSONDumpOptions)(InitializerContext* context) { - Status ret = storeBSONDumpOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - std::cerr << ret.toString() << std::endl; - std::cerr << "try '" << context->args()[0] << " --help' for more information" - << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); - } } diff --git a/src/mongo/tools/bsondump_options_init.cpp b/src/mongo/tools/bsondump_options_init.cpp new file mode 100644 index 00000000000..eed5baa82bc --- /dev/null +++ b/src/mongo/tools/bsondump_options_init.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 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/bsondump_options.h" + +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(BSONDumpOptions)(InitializerContext* context) { + return addBSONDumpOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(BSONDumpOptions)(InitializerContext* context) { + if (handlePreValidationBSONDumpOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); + } + Status ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(BSONDumpOptions)(InitializerContext* context) { + Status ret = storeBSONDumpOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); + } +} diff --git a/src/mongo/tools/bsondump_options_test.cpp b/src/mongo/tools/bsondump_options_test.cpp new file mode 100644 index 00000000000..ff65fc012ef --- /dev/null +++ b/src/mongo/tools/bsondump_options_test.cpp @@ -0,0 +1,211 @@ +/* Copyright 2013 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/tools/bsondump_options.h" + +#include "mongo/bson/util/builder.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace { + + namespace moe = ::mongo::optionenvironment; + + TEST(Registration, RegisterAllOptions) { + + moe::OptionSection options; + + ASSERT_OK(::mongo::addBSONDumpOptions(&options)); + + std::vector<moe::OptionDescription> options_vector; + ASSERT_OK(options.getAllOptions(&options_vector)); + + for(std::vector<moe::OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_dottedName == "help") { + ASSERT_EQUALS(iterator->_singleName, "help"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "produce help message"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "verbose") { + ASSERT_EQUALS(iterator->_singleName, "verbose,v"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "be more verbose (include multiple times for more verbosity e.g. -vvvvv)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "quiet") { + ASSERT_EQUALS(iterator->_singleName, "quiet"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "silence all non error diagnostic messages"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "version") { + ASSERT_EQUALS(iterator->_singleName, "version"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "print the program's version and exit"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vv") { + ASSERT_EQUALS(iterator->_singleName, "vv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvv") { + ASSERT_EQUALS(iterator->_singleName, "vvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "objcheck") { + ASSERT_EQUALS(iterator->_singleName, "objcheck"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "validate object before inserting (default)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "noobjcheck") { + ASSERT_EQUALS(iterator->_singleName, "noobjcheck"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "don't validate object before inserting"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "filter") { + ASSERT_EQUALS(iterator->_singleName, "filter"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "filter to apply before inserting"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "type") { + ASSERT_EQUALS(iterator->_singleName, "type"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "type of output: json,debug"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("json")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "file") { + ASSERT_EQUALS(iterator->_singleName, "file"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "hidden description"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else { + ::mongo::StringBuilder sb; + sb << "Found extra option: " << iterator->_dottedName << + " which we did not register"; + FAIL(sb.str()); + } + } + } + +} // namespace diff --git a/src/mongo/tools/mongobridge_options.cpp b/src/mongo/tools/mongobridge_options.cpp index 180632b7a9c..862d8b6a1b3 100644 --- a/src/mongo/tools/mongobridge_options.cpp +++ b/src/mongo/tools/mongobridge_options.cpp @@ -17,7 +17,6 @@ #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 { @@ -90,30 +89,4 @@ namespace mongo { return Status::OK(); } - MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoBridgeOptions)(InitializerContext* context) { - return addMongoBridgeOptions(&moe::startupOptions); - } - - MONGO_STARTUP_OPTIONS_VALIDATE(MongoBridgeOptions)(InitializerContext* context) { - if (handlePreValidationMongoBridgeOptions(moe::startupOptionsParsed)) { - ::_exit(EXIT_SUCCESS); - } - Status ret = moe::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); - } - - MONGO_STARTUP_OPTIONS_STORE(MongoBridgeOptions)(InitializerContext* context) { - Status ret = storeMongoBridgeOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - std::cerr << ret.toString() << std::endl; - std::cerr << "try '" << context->args()[0] << " --help' for more information" - << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); - } -} - +} // namespace mongo diff --git a/src/mongo/tools/mongobridge_options_init.cpp b/src/mongo/tools/mongobridge_options_init.cpp new file mode 100644 index 00000000000..d966a27d7f5 --- /dev/null +++ b/src/mongo/tools/mongobridge_options_init.cpp @@ -0,0 +1,49 @@ +/* + * 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/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoBridgeOptions)(InitializerContext* context) { + return addMongoBridgeOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(MongoBridgeOptions)(InitializerContext* context) { + if (handlePreValidationMongoBridgeOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); + } + Status ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(MongoBridgeOptions)(InitializerContext* context) { + Status ret = storeMongoBridgeOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); + } +} + diff --git a/src/mongo/tools/mongobridge_options_test.cpp b/src/mongo/tools/mongobridge_options_test.cpp new file mode 100644 index 00000000000..12bbd37cd9d --- /dev/null +++ b/src/mongo/tools/mongobridge_options_test.cpp @@ -0,0 +1,85 @@ +/* Copyright 2013 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/tools/mongobridge_options.h" + +#include "mongo/bson/util/builder.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace { + + namespace moe = ::mongo::optionenvironment; + + TEST(Registration, RegisterAllOptions) { + + moe::OptionSection options; + + ASSERT_OK(::mongo::addMongoBridgeOptions(&options)); + + std::vector<moe::OptionDescription> options_vector; + ASSERT_OK(options.getAllOptions(&options_vector)); + + for(std::vector<moe::OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_dottedName == "help") { + ASSERT_EQUALS(iterator->_singleName, "help"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "produce help message"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "port") { + ASSERT_EQUALS(iterator->_singleName, "port"); + ASSERT_EQUALS(iterator->_type, moe::Int); + ASSERT_EQUALS(iterator->_description, "port to listen for mongo messages"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "dest") { + ASSERT_EQUALS(iterator->_singleName, "dest"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "uri of remote mongod instance"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "delay") { + ASSERT_EQUALS(iterator->_singleName, "delay"); + ASSERT_EQUALS(iterator->_type, moe::Int); + ASSERT_EQUALS(iterator->_description, "transfer delay in milliseconds (default = 0)"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(0); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else { + ::mongo::StringBuilder sb; + sb << "Found extra option: " << iterator->_dottedName << + " which we did not register"; + FAIL(sb.str()); + } + } + } + +} // namespace diff --git a/src/mongo/tools/mongodump_options.cpp b/src/mongo/tools/mongodump_options.cpp index b924fcba2d5..592400e6523 100644 --- a/src/mongo/tools/mongodump_options.cpp +++ b/src/mongo/tools/mongodump_options.cpp @@ -18,7 +18,6 @@ #include "mongo/base/status.h" #include "mongo/util/log.h" -#include "mongo/util/options_parser/startup_option_init.h" #include "mongo/util/options_parser/startup_options.h" namespace mongo { @@ -137,29 +136,4 @@ namespace mongo { return Status::OK(); } - MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoDumpOptions)(InitializerContext* context) { - return addMongoDumpOptions(&moe::startupOptions); - } - - MONGO_STARTUP_OPTIONS_VALIDATE(MongoDumpOptions)(InitializerContext* context) { - if (handlePreValidationMongoDumpOptions(moe::startupOptionsParsed)) { - ::_exit(EXIT_SUCCESS); - } - Status ret = moe::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); - } - - MONGO_STARTUP_OPTIONS_STORE(MongoDumpOptions)(InitializerContext* context) { - Status ret = storeMongoDumpOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - std::cerr << ret.toString() << std::endl; - std::cerr << "try '" << context->args()[0] << " --help' for more information" - << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); - } } diff --git a/src/mongo/tools/mongodump_options_init.cpp b/src/mongo/tools/mongodump_options_init.cpp new file mode 100644 index 00000000000..189a9e59a2a --- /dev/null +++ b/src/mongo/tools/mongodump_options_init.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 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/mongodump_options.h" + +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoDumpOptions)(InitializerContext* context) { + return addMongoDumpOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(MongoDumpOptions)(InitializerContext* context) { + if (handlePreValidationMongoDumpOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); + } + Status ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(MongoDumpOptions)(InitializerContext* context) { + Status ret = storeMongoDumpOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); + } +} diff --git a/src/mongo/tools/mongodump_options_test.cpp b/src/mongo/tools/mongodump_options_test.cpp new file mode 100644 index 00000000000..173c105214c --- /dev/null +++ b/src/mongo/tools/mongodump_options_test.cpp @@ -0,0 +1,378 @@ +/* Copyright 2013 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/tools/mongodump_options.h" + +#include "mongo/bson/util/builder.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace { + + namespace moe = ::mongo::optionenvironment; + + TEST(Registration, RegisterAllOptions) { + + moe::OptionSection options; + + ASSERT_OK(::mongo::addMongoDumpOptions(&options)); + + std::vector<moe::OptionDescription> options_vector; + ASSERT_OK(options.getAllOptions(&options_vector)); + + for(std::vector<moe::OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_dottedName == "help") { + ASSERT_EQUALS(iterator->_singleName, "help"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "produce help message"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "verbose") { + ASSERT_EQUALS(iterator->_singleName, "verbose,v"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "be more verbose (include multiple times for more verbosity e.g. -vvvvv)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "quiet") { + ASSERT_EQUALS(iterator->_singleName, "quiet"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "silence all non error diagnostic messages"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "version") { + ASSERT_EQUALS(iterator->_singleName, "version"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "print the program's version and exit"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vv") { + ASSERT_EQUALS(iterator->_singleName, "vv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvv") { + ASSERT_EQUALS(iterator->_singleName, "vvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "host") { + ASSERT_EQUALS(iterator->_singleName, "host,h"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "mongo host to connect to ( <set name>/s1,s2 for sets)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "port") { + ASSERT_EQUALS(iterator->_singleName, "port"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "server port. Can also use --host hostname:port"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ipv6") { + ASSERT_EQUALS(iterator->_singleName, "ipv6"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable IPv6 support (disabled by default)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "username") { + ASSERT_EQUALS(iterator->_singleName, "username,u"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "username"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "password") { + ASSERT_EQUALS(iterator->_singleName, "password,p"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + moe::Value implicitVal(std::string("")); + ASSERT_TRUE(iterator->_implicit.equal(implicitVal)); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationDatabase") { + ASSERT_EQUALS(iterator->_singleName, "authenticationDatabase"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "user source (defaults to dbname)"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationMechanism") { + ASSERT_EQUALS(iterator->_singleName, "authenticationMechanism"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "authentication mechanism"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("MONGODB-CR")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "dbpath") { + ASSERT_EQUALS(iterator->_singleName, "dbpath"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "directly access mongod database files in the given path, instead of connecting to a mongod server - needs to lock the data directory, so cannot be used if a mongod is currently accessing the same path"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "directoryperdb") { + ASSERT_EQUALS(iterator->_singleName, "directoryperdb"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "each db is in a separate directory (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "journal") { + ASSERT_EQUALS(iterator->_singleName, "journal"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable journaling (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "db") { + ASSERT_EQUALS(iterator->_singleName, "db,d"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "database to use"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "collection") { + ASSERT_EQUALS(iterator->_singleName, "collection,c"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "collection to use (some commands)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "out") { + ASSERT_EQUALS(iterator->_singleName, "out,o"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "output directory or \"-\" for stdout"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("dump")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "query") { + ASSERT_EQUALS(iterator->_singleName, "query,q"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "json query"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "oplog") { + ASSERT_EQUALS(iterator->_singleName, "oplog"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "Use oplog for point-in-time snapshotting"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "repair") { + ASSERT_EQUALS(iterator->_singleName, "repair"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "try to recover a crashed database"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "forceTableScan") { + ASSERT_EQUALS(iterator->_singleName, "forceTableScan"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "force a table scan (do not use $snapshot)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#ifdef MONGO_SSL + else if (iterator->_dottedName == "ssl") { + ASSERT_EQUALS(iterator->_singleName, "ssl"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "use SSL for all connections"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CAFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCAFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Authority file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyFile") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "PEM certificate/key file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyPassword") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyPassword"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password for key in PEM file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CRLFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCRLFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Revocation List file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.FIPSMode") { + ASSERT_EQUALS(iterator->_singleName, "sslFIPSMode"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "activate FIPS 140-2 mode at startup"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#endif + else { + ::mongo::StringBuilder sb; + sb << "Found extra option: " << iterator->_dottedName << + " which we did not register"; + FAIL(sb.str()); + } + } + } + +} // namespace diff --git a/src/mongo/tools/mongoexport_options.cpp b/src/mongo/tools/mongoexport_options.cpp index 2b1f26e53ae..b028b5e0285 100644 --- a/src/mongo/tools/mongoexport_options.cpp +++ b/src/mongo/tools/mongoexport_options.cpp @@ -17,7 +17,6 @@ #include "mongo/tools/mongoexport_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 { @@ -150,29 +149,4 @@ namespace mongo { return Status::OK(); } - MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoExportOptions)(InitializerContext* context) { - return addMongoExportOptions(&moe::startupOptions); - } - - MONGO_STARTUP_OPTIONS_VALIDATE(MongoExportOptions)(InitializerContext* context) { - if (handlePreValidationMongoExportOptions(moe::startupOptionsParsed)) { - ::_exit(EXIT_SUCCESS); - } - Status ret = moe::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); - } - - MONGO_STARTUP_OPTIONS_STORE(MongoExportOptions)(InitializerContext* context) { - Status ret = storeMongoExportOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - std::cerr << ret.toString() << std::endl; - std::cerr << "try '" << context->args()[0] << " --help' for more information" - << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); - } } diff --git a/src/mongo/tools/mongoexport_options_init.cpp b/src/mongo/tools/mongoexport_options_init.cpp new file mode 100644 index 00000000000..d18b0771716 --- /dev/null +++ b/src/mongo/tools/mongoexport_options_init.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 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/mongoexport_options.h" + +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoExportOptions)(InitializerContext* context) { + return addMongoExportOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(MongoExportOptions)(InitializerContext* context) { + if (handlePreValidationMongoExportOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); + } + Status ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(MongoExportOptions)(InitializerContext* context) { + Status ret = storeMongoExportOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); + } +} diff --git a/src/mongo/tools/mongoexport_options_test.cpp b/src/mongo/tools/mongoexport_options_test.cpp new file mode 100644 index 00000000000..2886109b5c0 --- /dev/null +++ b/src/mongo/tools/mongoexport_options_test.cpp @@ -0,0 +1,425 @@ +/* Copyright 2013 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/tools/mongoexport_options.h" + +#include "mongo/bson/util/builder.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace { + + namespace moe = ::mongo::optionenvironment; + + TEST(Registration, RegisterAllOptions) { + + moe::OptionSection options; + + ASSERT_OK(::mongo::addMongoExportOptions(&options)); + + std::vector<moe::OptionDescription> options_vector; + ASSERT_OK(options.getAllOptions(&options_vector)); + + for(std::vector<moe::OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_dottedName == "help") { + ASSERT_EQUALS(iterator->_singleName, "help"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "produce help message"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "verbose") { + ASSERT_EQUALS(iterator->_singleName, "verbose,v"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "be more verbose (include multiple times for more verbosity e.g. -vvvvv)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "quiet") { + ASSERT_EQUALS(iterator->_singleName, "quiet"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "silence all non error diagnostic messages"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "version") { + ASSERT_EQUALS(iterator->_singleName, "version"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "print the program's version and exit"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vv") { + ASSERT_EQUALS(iterator->_singleName, "vv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvv") { + ASSERT_EQUALS(iterator->_singleName, "vvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "host") { + ASSERT_EQUALS(iterator->_singleName, "host,h"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "mongo host to connect to ( <set name>/s1,s2 for sets)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "port") { + ASSERT_EQUALS(iterator->_singleName, "port"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "server port. Can also use --host hostname:port"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ipv6") { + ASSERT_EQUALS(iterator->_singleName, "ipv6"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable IPv6 support (disabled by default)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "username") { + ASSERT_EQUALS(iterator->_singleName, "username,u"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "username"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "password") { + ASSERT_EQUALS(iterator->_singleName, "password,p"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + moe::Value implicitVal(std::string("")); + ASSERT_TRUE(iterator->_implicit.equal(implicitVal)); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationDatabase") { + ASSERT_EQUALS(iterator->_singleName, "authenticationDatabase"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "user source (defaults to dbname)"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationMechanism") { + ASSERT_EQUALS(iterator->_singleName, "authenticationMechanism"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "authentication mechanism"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("MONGODB-CR")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "dbpath") { + ASSERT_EQUALS(iterator->_singleName, "dbpath"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "directly access mongod database files in the given path, instead of connecting to a mongod server - needs to lock the data directory, so cannot be used if a mongod is currently accessing the same path"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "directoryperdb") { + ASSERT_EQUALS(iterator->_singleName, "directoryperdb"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "each db is in a separate directory (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "journal") { + ASSERT_EQUALS(iterator->_singleName, "journal"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable journaling (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "db") { + ASSERT_EQUALS(iterator->_singleName, "db,d"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "database to use"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "collection") { + ASSERT_EQUALS(iterator->_singleName, "collection,c"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "collection to use (some commands)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "fields") { + ASSERT_EQUALS(iterator->_singleName, "fields,f"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "comma separated list of field names e.g. -f name,age"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "fieldFile") { + ASSERT_EQUALS(iterator->_singleName, "fieldFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "file with field names - 1 per line"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "query") { + ASSERT_EQUALS(iterator->_singleName, "query,q"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "query filter, as a JSON string"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "csv") { + ASSERT_EQUALS(iterator->_singleName, "csv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "export to csv instead of json"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "out") { + ASSERT_EQUALS(iterator->_singleName, "out,o"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "output file; if not specified, stdout is used"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "jsonArray") { + ASSERT_EQUALS(iterator->_singleName, "jsonArray"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "output to a json array rather than one object per line"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "slaveOk") { + ASSERT_EQUALS(iterator->_singleName, "slaveOk,k"); + ASSERT_EQUALS(iterator->_type, moe::Bool); + ASSERT_EQUALS(iterator->_description, "use secondaries for export if available, default true"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(true); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "forceTableScan") { + ASSERT_EQUALS(iterator->_singleName, "forceTableScan"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "force a table scan (do not use $snapshot)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "skip") { + ASSERT_EQUALS(iterator->_singleName, "skip"); + ASSERT_EQUALS(iterator->_type, moe::Int); + ASSERT_EQUALS(iterator->_description, "documents to skip, default 0"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(0); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "limit") { + ASSERT_EQUALS(iterator->_singleName, "limit"); + ASSERT_EQUALS(iterator->_type, moe::Int); + ASSERT_EQUALS(iterator->_description, "limit the numbers of documents returned, default all"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(0); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#ifdef MONGO_SSL + else if (iterator->_dottedName == "ssl") { + ASSERT_EQUALS(iterator->_singleName, "ssl"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "use SSL for all connections"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CAFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCAFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Authority file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyFile") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "PEM certificate/key file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyPassword") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyPassword"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password for key in PEM file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CRLFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCRLFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Revocation List file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.FIPSMode") { + ASSERT_EQUALS(iterator->_singleName, "sslFIPSMode"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "activate FIPS 140-2 mode at startup"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#endif + else { + ::mongo::StringBuilder sb; + sb << "Found extra option: " << iterator->_dottedName << + " which we did not register"; + FAIL(sb.str()); + } + } + } + +} // namespace diff --git a/src/mongo/tools/mongofiles_options.cpp b/src/mongo/tools/mongofiles_options.cpp index da5ffead5c4..8e5c5972a43 100644 --- a/src/mongo/tools/mongofiles_options.cpp +++ b/src/mongo/tools/mongofiles_options.cpp @@ -17,7 +17,6 @@ #include "mongo/tools/mongofiles_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 { @@ -117,29 +116,4 @@ namespace mongo { return Status::OK(); } - MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoFilesOptions)(InitializerContext* context) { - return addMongoFilesOptions(&moe::startupOptions); - } - - MONGO_STARTUP_OPTIONS_VALIDATE(MongoFilesOptions)(InitializerContext* context) { - if (handlePreValidationMongoFilesOptions(moe::startupOptionsParsed)) { - ::_exit(EXIT_SUCCESS); - } - Status ret = moe::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); - } - - MONGO_STARTUP_OPTIONS_STORE(MongoFilesOptions)(InitializerContext* context) { - Status ret = storeMongoFilesOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - std::cerr << ret.toString() << std::endl; - std::cerr << "try '" << context->args()[0] << " --help' for more information" - << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); - } } diff --git a/src/mongo/tools/mongofiles_options_init.cpp b/src/mongo/tools/mongofiles_options_init.cpp new file mode 100644 index 00000000000..9b6a5f9d9d3 --- /dev/null +++ b/src/mongo/tools/mongofiles_options_init.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 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/mongofiles_options.h" + +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoFilesOptions)(InitializerContext* context) { + return addMongoFilesOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(MongoFilesOptions)(InitializerContext* context) { + if (handlePreValidationMongoFilesOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); + } + Status ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(MongoFilesOptions)(InitializerContext* context) { + Status ret = storeMongoFilesOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); + } +} diff --git a/src/mongo/tools/mongofiles_options_test.cpp b/src/mongo/tools/mongofiles_options_test.cpp new file mode 100644 index 00000000000..ba7aaf03382 --- /dev/null +++ b/src/mongo/tools/mongofiles_options_test.cpp @@ -0,0 +1,377 @@ +/* Copyright 2013 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/tools/mongofiles_options.h" + +#include "mongo/bson/util/builder.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace { + + namespace moe = ::mongo::optionenvironment; + + TEST(Registration, RegisterAllOptions) { + + moe::OptionSection options; + + ASSERT_OK(::mongo::addMongoFilesOptions(&options)); + + std::vector<moe::OptionDescription> options_vector; + ASSERT_OK(options.getAllOptions(&options_vector)); + + for(std::vector<moe::OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_dottedName == "help") { + ASSERT_EQUALS(iterator->_singleName, "help"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "produce help message"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "verbose") { + ASSERT_EQUALS(iterator->_singleName, "verbose,v"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "be more verbose (include multiple times for more verbosity e.g. -vvvvv)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "quiet") { + ASSERT_EQUALS(iterator->_singleName, "quiet"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "silence all non error diagnostic messages"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "version") { + ASSERT_EQUALS(iterator->_singleName, "version"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "print the program's version and exit"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vv") { + ASSERT_EQUALS(iterator->_singleName, "vv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvv") { + ASSERT_EQUALS(iterator->_singleName, "vvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "host") { + ASSERT_EQUALS(iterator->_singleName, "host,h"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "mongo host to connect to ( <set name>/s1,s2 for sets)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "port") { + ASSERT_EQUALS(iterator->_singleName, "port"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "server port. Can also use --host hostname:port"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ipv6") { + ASSERT_EQUALS(iterator->_singleName, "ipv6"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable IPv6 support (disabled by default)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "username") { + ASSERT_EQUALS(iterator->_singleName, "username,u"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "username"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "password") { + ASSERT_EQUALS(iterator->_singleName, "password,p"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + moe::Value implicitVal(std::string("")); + ASSERT_TRUE(iterator->_implicit.equal(implicitVal)); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationDatabase") { + ASSERT_EQUALS(iterator->_singleName, "authenticationDatabase"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "user source (defaults to dbname)"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationMechanism") { + ASSERT_EQUALS(iterator->_singleName, "authenticationMechanism"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "authentication mechanism"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("MONGODB-CR")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "dbpath") { + ASSERT_EQUALS(iterator->_singleName, "dbpath"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "directly access mongod database files in the given path, instead of connecting to a mongod server - needs to lock the data directory, so cannot be used if a mongod is currently accessing the same path"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "directoryperdb") { + ASSERT_EQUALS(iterator->_singleName, "directoryperdb"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "each db is in a separate directory (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "journal") { + ASSERT_EQUALS(iterator->_singleName, "journal"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable journaling (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "db") { + ASSERT_EQUALS(iterator->_singleName, "db,d"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "database to use"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "collection") { + ASSERT_EQUALS(iterator->_singleName, "collection,c"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "collection to use (some commands)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "local") { + ASSERT_EQUALS(iterator->_singleName, "local,l"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "local filename for put|get (default is to use the same name as 'gridfs filename')"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "type") { + ASSERT_EQUALS(iterator->_singleName, "type,t"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "MIME type for put (default is to omit)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "replace") { + ASSERT_EQUALS(iterator->_singleName, "replace,r"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "Remove other files with same name after PUT"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "command") { + ASSERT_EQUALS(iterator->_singleName, "command"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "hidden description"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "file") { + ASSERT_EQUALS(iterator->_singleName, "file"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "hidden description"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#ifdef MONGO_SSL + else if (iterator->_dottedName == "ssl") { + ASSERT_EQUALS(iterator->_singleName, "ssl"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "use SSL for all connections"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CAFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCAFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Authority file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyFile") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "PEM certificate/key file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyPassword") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyPassword"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password for key in PEM file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CRLFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCRLFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Revocation List file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.FIPSMode") { + ASSERT_EQUALS(iterator->_singleName, "sslFIPSMode"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "activate FIPS 140-2 mode at startup"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#endif + else { + ::mongo::StringBuilder sb; + sb << "Found extra option: " << iterator->_dottedName << + " which we did not register"; + FAIL(sb.str()); + } + } + } + +} // namespace diff --git a/src/mongo/tools/mongoimport_options.cpp b/src/mongo/tools/mongoimport_options.cpp index 534f69e66e4..de400bf139a 100644 --- a/src/mongo/tools/mongoimport_options.cpp +++ b/src/mongo/tools/mongoimport_options.cpp @@ -17,7 +17,6 @@ #include "mongo/tools/mongoimport_options.h" #include "mongo/base/status.h" -#include "mongo/util/options_parser/startup_option_init.h" #include "mongo/util/options_parser/startup_options.h" #include "mongo/util/text.h" @@ -172,29 +171,4 @@ namespace mongo { return Status::OK(); } - MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoImportOptions)(InitializerContext* context) { - return addMongoImportOptions(&moe::startupOptions); - } - - MONGO_STARTUP_OPTIONS_VALIDATE(MongoImportOptions)(InitializerContext* context) { - if (handlePreValidationMongoImportOptions(moe::startupOptionsParsed)) { - ::_exit(EXIT_SUCCESS); - } - Status ret = moe::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); - } - - MONGO_STARTUP_OPTIONS_STORE(MongoImportOptions)(InitializerContext* context) { - Status ret = storeMongoImportOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - std::cerr << ret.toString() << std::endl; - std::cerr << "try '" << context->args()[0] << " --help' for more information" - << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); - } } diff --git a/src/mongo/tools/mongoimport_options_init.cpp b/src/mongo/tools/mongoimport_options_init.cpp new file mode 100644 index 00000000000..054f1595c1b --- /dev/null +++ b/src/mongo/tools/mongoimport_options_init.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 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/mongoimport_options.h" + +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoImportOptions)(InitializerContext* context) { + return addMongoImportOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(MongoImportOptions)(InitializerContext* context) { + if (handlePreValidationMongoImportOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); + } + Status ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(MongoImportOptions)(InitializerContext* context) { + Status ret = storeMongoImportOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); + } +} diff --git a/src/mongo/tools/mongoimport_options_test.cpp b/src/mongo/tools/mongoimport_options_test.cpp new file mode 100644 index 00000000000..c3dabaade50 --- /dev/null +++ b/src/mongo/tools/mongoimport_options_test.cpp @@ -0,0 +1,440 @@ +/* Copyright 2013 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/tools/mongoimport_options.h" + +#include "mongo/bson/util/builder.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace { + + namespace moe = ::mongo::optionenvironment; + + TEST(Registration, RegisterAllOptions) { + + moe::OptionSection options; + + ASSERT_OK(::mongo::addMongoImportOptions(&options)); + + std::vector<moe::OptionDescription> options_vector; + ASSERT_OK(options.getAllOptions(&options_vector)); + + for(std::vector<moe::OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_dottedName == "help") { + ASSERT_EQUALS(iterator->_singleName, "help"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "produce help message"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "verbose") { + ASSERT_EQUALS(iterator->_singleName, "verbose,v"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "be more verbose (include multiple times for more verbosity e.g. -vvvvv)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "quiet") { + ASSERT_EQUALS(iterator->_singleName, "quiet"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "silence all non error diagnostic messages"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "version") { + ASSERT_EQUALS(iterator->_singleName, "version"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "print the program's version and exit"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vv") { + ASSERT_EQUALS(iterator->_singleName, "vv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvv") { + ASSERT_EQUALS(iterator->_singleName, "vvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "host") { + ASSERT_EQUALS(iterator->_singleName, "host,h"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "mongo host to connect to ( <set name>/s1,s2 for sets)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "port") { + ASSERT_EQUALS(iterator->_singleName, "port"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "server port. Can also use --host hostname:port"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ipv6") { + ASSERT_EQUALS(iterator->_singleName, "ipv6"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable IPv6 support (disabled by default)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "username") { + ASSERT_EQUALS(iterator->_singleName, "username,u"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "username"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "password") { + ASSERT_EQUALS(iterator->_singleName, "password,p"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + moe::Value implicitVal(std::string("")); + ASSERT_TRUE(iterator->_implicit.equal(implicitVal)); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationDatabase") { + ASSERT_EQUALS(iterator->_singleName, "authenticationDatabase"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "user source (defaults to dbname)"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationMechanism") { + ASSERT_EQUALS(iterator->_singleName, "authenticationMechanism"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "authentication mechanism"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("MONGODB-CR")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "dbpath") { + ASSERT_EQUALS(iterator->_singleName, "dbpath"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "directly access mongod database files in the given path, instead of connecting to a mongod server - needs to lock the data directory, so cannot be used if a mongod is currently accessing the same path"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "directoryperdb") { + ASSERT_EQUALS(iterator->_singleName, "directoryperdb"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "each db is in a separate directory (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "journal") { + ASSERT_EQUALS(iterator->_singleName, "journal"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable journaling (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "db") { + ASSERT_EQUALS(iterator->_singleName, "db,d"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "database to use"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "collection") { + ASSERT_EQUALS(iterator->_singleName, "collection,c"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "collection to use (some commands)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "fields") { + ASSERT_EQUALS(iterator->_singleName, "fields,f"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "comma separated list of field names e.g. -f name,age"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "fieldFile") { + ASSERT_EQUALS(iterator->_singleName, "fieldFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "file with field names - 1 per line"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ignoreBlanks") { + ASSERT_EQUALS(iterator->_singleName, "ignoreBlanks"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "if given, empty fields in csv and tsv will be ignored"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "type") { + ASSERT_EQUALS(iterator->_singleName, "type"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "type of file to import. default: json (json,csv,tsv)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "file") { + ASSERT_EQUALS(iterator->_singleName, "file"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "file to import from; if not specified stdin is used"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "drop") { + ASSERT_EQUALS(iterator->_singleName, "drop"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "drop collection first "); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "headerline") { + ASSERT_EQUALS(iterator->_singleName, "headerline"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "first line in input file is a header (CSV and TSV only)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "upsert") { + ASSERT_EQUALS(iterator->_singleName, "upsert"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "insert or update objects that already exist"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "upsertFields") { + ASSERT_EQUALS(iterator->_singleName, "upsertFields"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "comma-separated fields for the query part of the upsert. You should make sure this is indexed"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "stopOnError") { + ASSERT_EQUALS(iterator->_singleName, "stopOnError"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "stop importing at first error rather than continuing"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "jsonArray") { + ASSERT_EQUALS(iterator->_singleName, "jsonArray"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "load a json array, not one item per line. Currently limited to 16MB."); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "noimport") { + ASSERT_EQUALS(iterator->_singleName, "noimport"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "don't actually import. useful for benchmarking parser"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#ifdef MONGO_SSL + else if (iterator->_dottedName == "ssl") { + ASSERT_EQUALS(iterator->_singleName, "ssl"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "use SSL for all connections"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CAFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCAFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Authority file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyFile") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "PEM certificate/key file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyPassword") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyPassword"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password for key in PEM file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CRLFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCRLFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Revocation List file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.FIPSMode") { + ASSERT_EQUALS(iterator->_singleName, "sslFIPSMode"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "activate FIPS 140-2 mode at startup"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#endif + else { + ::mongo::StringBuilder sb; + sb << "Found extra option: " << iterator->_dottedName << + " which we did not register"; + FAIL(sb.str()); + } + } + } + +} // namespace diff --git a/src/mongo/tools/mongooplog_options.cpp b/src/mongo/tools/mongooplog_options.cpp index 3292436e4b4..bfac312efcf 100644 --- a/src/mongo/tools/mongooplog_options.cpp +++ b/src/mongo/tools/mongooplog_options.cpp @@ -18,7 +18,6 @@ #include "mongo/base/status.h" #include "mongo/util/log.h" -#include "mongo/util/options_parser/startup_option_init.h" #include "mongo/util/options_parser/startup_options.h" namespace mongo { @@ -101,29 +100,4 @@ namespace mongo { return Status::OK(); } - MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoOplogOptions)(InitializerContext* context) { - return addMongoOplogOptions(&moe::startupOptions); - } - - MONGO_STARTUP_OPTIONS_VALIDATE(MongoOplogOptions)(InitializerContext* context) { - if (handlePreValidationMongoOplogOptions(moe::startupOptionsParsed)) { - ::_exit(EXIT_SUCCESS); - } - Status ret = moe::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); - } - - MONGO_STARTUP_OPTIONS_STORE(MongoOplogOptions)(InitializerContext* context) { - Status ret = storeMongoOplogOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - std::cerr << ret.toString() << std::endl; - std::cerr << "try '" << context->args()[0] << " --help' for more information" - << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); - } } diff --git a/src/mongo/tools/mongooplog_options_init.cpp b/src/mongo/tools/mongooplog_options_init.cpp new file mode 100644 index 00000000000..85685872ce7 --- /dev/null +++ b/src/mongo/tools/mongooplog_options_init.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 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/mongooplog_options.h" + +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoOplogOptions)(InitializerContext* context) { + return addMongoOplogOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(MongoOplogOptions)(InitializerContext* context) { + if (handlePreValidationMongoOplogOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); + } + Status ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(MongoOplogOptions)(InitializerContext* context) { + Status ret = storeMongoOplogOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); + } +} diff --git a/src/mongo/tools/mongooplog_options_test.cpp b/src/mongo/tools/mongooplog_options_test.cpp new file mode 100644 index 00000000000..bd00a7e6654 --- /dev/null +++ b/src/mongo/tools/mongooplog_options_test.cpp @@ -0,0 +1,360 @@ +/* Copyright 2013 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/tools/mongooplog_options.h" + +#include "mongo/bson/util/builder.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace { + + namespace moe = ::mongo::optionenvironment; + + TEST(Registration, RegisterAllOptions) { + + moe::OptionSection options; + + ASSERT_OK(::mongo::addMongoOplogOptions(&options)); + + std::vector<moe::OptionDescription> options_vector; + ASSERT_OK(options.getAllOptions(&options_vector)); + + for(std::vector<moe::OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_dottedName == "help") { + ASSERT_EQUALS(iterator->_singleName, "help"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "produce help message"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "verbose") { + ASSERT_EQUALS(iterator->_singleName, "verbose,v"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "be more verbose (include multiple times for more verbosity e.g. -vvvvv)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "quiet") { + ASSERT_EQUALS(iterator->_singleName, "quiet"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "silence all non error diagnostic messages"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "version") { + ASSERT_EQUALS(iterator->_singleName, "version"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "print the program's version and exit"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vv") { + ASSERT_EQUALS(iterator->_singleName, "vv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvv") { + ASSERT_EQUALS(iterator->_singleName, "vvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "host") { + ASSERT_EQUALS(iterator->_singleName, "host,h"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "mongo host to connect to ( <set name>/s1,s2 for sets)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "port") { + ASSERT_EQUALS(iterator->_singleName, "port"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "server port. Can also use --host hostname:port"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ipv6") { + ASSERT_EQUALS(iterator->_singleName, "ipv6"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable IPv6 support (disabled by default)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "username") { + ASSERT_EQUALS(iterator->_singleName, "username,u"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "username"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "password") { + ASSERT_EQUALS(iterator->_singleName, "password,p"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + moe::Value implicitVal(std::string("")); + ASSERT_TRUE(iterator->_implicit.equal(implicitVal)); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationDatabase") { + ASSERT_EQUALS(iterator->_singleName, "authenticationDatabase"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "user source (defaults to dbname)"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationMechanism") { + ASSERT_EQUALS(iterator->_singleName, "authenticationMechanism"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "authentication mechanism"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("MONGODB-CR")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "dbpath") { + ASSERT_EQUALS(iterator->_singleName, "dbpath"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "directly access mongod database files in the given path, instead of connecting to a mongod server - needs to lock the data directory, so cannot be used if a mongod is currently accessing the same path"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "directoryperdb") { + ASSERT_EQUALS(iterator->_singleName, "directoryperdb"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "each db is in a separate directory (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "journal") { + ASSERT_EQUALS(iterator->_singleName, "journal"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable journaling (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "db") { + ASSERT_EQUALS(iterator->_singleName, "db,d"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "database to use"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "collection") { + ASSERT_EQUALS(iterator->_singleName, "collection,c"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "collection to use (some commands)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "seconds") { + ASSERT_EQUALS(iterator->_singleName, "seconds,s"); + ASSERT_EQUALS(iterator->_type, moe::Int); + ASSERT_EQUALS(iterator->_description, "seconds to go back default:86400"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "from") { + ASSERT_EQUALS(iterator->_singleName, "from"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "host to pull from"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "oplogns") { + ASSERT_EQUALS(iterator->_singleName, "oplogns"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "ns to pull from"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("local.oplog.rs")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#ifdef MONGO_SSL + else if (iterator->_dottedName == "ssl") { + ASSERT_EQUALS(iterator->_singleName, "ssl"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "use SSL for all connections"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CAFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCAFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Authority file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyFile") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "PEM certificate/key file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyPassword") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyPassword"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password for key in PEM file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CRLFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCRLFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Revocation List file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.FIPSMode") { + ASSERT_EQUALS(iterator->_singleName, "sslFIPSMode"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "activate FIPS 140-2 mode at startup"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#endif + else { + ::mongo::StringBuilder sb; + sb << "Found extra option: " << iterator->_dottedName << + " which we did not register"; + FAIL(sb.str()); + } + } + } + +} // namespace diff --git a/src/mongo/tools/mongorestore_options.cpp b/src/mongo/tools/mongorestore_options.cpp index c1ad0e791f6..dac7a25a927 100644 --- a/src/mongo/tools/mongorestore_options.cpp +++ b/src/mongo/tools/mongorestore_options.cpp @@ -17,7 +17,6 @@ #include "mongo/tools/mongorestore_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 { @@ -156,29 +155,4 @@ namespace mongo { return Status::OK(); } - MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoRestoreOptions)(InitializerContext* context) { - return addMongoRestoreOptions(&moe::startupOptions); - } - - MONGO_STARTUP_OPTIONS_VALIDATE(MongoRestoreOptions)(InitializerContext* context) { - if (handlePreValidationMongoRestoreOptions(moe::startupOptionsParsed)) { - ::_exit(EXIT_SUCCESS); - } - Status ret = moe::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); - } - - MONGO_STARTUP_OPTIONS_STORE(MongoRestoreOptions)(InitializerContext* context) { - Status ret = storeMongoRestoreOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - std::cerr << ret.toString() << std::endl; - std::cerr << "try '" << context->args()[0] << " --help' for more information" - << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); - } } diff --git a/src/mongo/tools/mongorestore_options_init.cpp b/src/mongo/tools/mongorestore_options_init.cpp new file mode 100644 index 00000000000..f03c9ea531a --- /dev/null +++ b/src/mongo/tools/mongorestore_options_init.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 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/mongorestore_options.h" + +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoRestoreOptions)(InitializerContext* context) { + return addMongoRestoreOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(MongoRestoreOptions)(InitializerContext* context) { + if (handlePreValidationMongoRestoreOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); + } + Status ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(MongoRestoreOptions)(InitializerContext* context) { + Status ret = storeMongoRestoreOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); + } +} diff --git a/src/mongo/tools/mongorestore_options_test.cpp b/src/mongo/tools/mongorestore_options_test.cpp new file mode 100644 index 00000000000..d1b854f86c4 --- /dev/null +++ b/src/mongo/tools/mongorestore_options_test.cpp @@ -0,0 +1,442 @@ +/* Copyright 2013 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/tools/mongorestore_options.h" + +#include "mongo/bson/util/builder.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace { + + namespace moe = ::mongo::optionenvironment; + + TEST(Registration, RegisterAllOptions) { + + moe::OptionSection options; + + ASSERT_OK(::mongo::addMongoRestoreOptions(&options)); + + std::vector<moe::OptionDescription> options_vector; + ASSERT_OK(options.getAllOptions(&options_vector)); + + for(std::vector<moe::OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_dottedName == "help") { + ASSERT_EQUALS(iterator->_singleName, "help"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "produce help message"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "verbose") { + ASSERT_EQUALS(iterator->_singleName, "verbose,v"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "be more verbose (include multiple times for more verbosity e.g. -vvvvv)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "quiet") { + ASSERT_EQUALS(iterator->_singleName, "quiet"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "silence all non error diagnostic messages"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "version") { + ASSERT_EQUALS(iterator->_singleName, "version"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "print the program's version and exit"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vv") { + ASSERT_EQUALS(iterator->_singleName, "vv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvv") { + ASSERT_EQUALS(iterator->_singleName, "vvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "host") { + ASSERT_EQUALS(iterator->_singleName, "host,h"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "mongo host to connect to ( <set name>/s1,s2 for sets)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "port") { + ASSERT_EQUALS(iterator->_singleName, "port"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "server port. Can also use --host hostname:port"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ipv6") { + ASSERT_EQUALS(iterator->_singleName, "ipv6"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable IPv6 support (disabled by default)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "username") { + ASSERT_EQUALS(iterator->_singleName, "username,u"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "username"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "password") { + ASSERT_EQUALS(iterator->_singleName, "password,p"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + moe::Value implicitVal(std::string("")); + ASSERT_TRUE(iterator->_implicit.equal(implicitVal)); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationDatabase") { + ASSERT_EQUALS(iterator->_singleName, "authenticationDatabase"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "user source (defaults to dbname)"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationMechanism") { + ASSERT_EQUALS(iterator->_singleName, "authenticationMechanism"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "authentication mechanism"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("MONGODB-CR")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "dbpath") { + ASSERT_EQUALS(iterator->_singleName, "dbpath"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "directly access mongod database files in the given path, instead of connecting to a mongod server - needs to lock the data directory, so cannot be used if a mongod is currently accessing the same path"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "directoryperdb") { + ASSERT_EQUALS(iterator->_singleName, "directoryperdb"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "each db is in a separate directory (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "journal") { + ASSERT_EQUALS(iterator->_singleName, "journal"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable journaling (relevant only if dbpath specified)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "db") { + ASSERT_EQUALS(iterator->_singleName, "db,d"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "database to use"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "collection") { + ASSERT_EQUALS(iterator->_singleName, "collection,c"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "collection to use (some commands)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "objcheck") { + ASSERT_EQUALS(iterator->_singleName, "objcheck"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "validate object before inserting (default)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "noobjcheck") { + ASSERT_EQUALS(iterator->_singleName, "noobjcheck"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "don't validate object before inserting"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "filter") { + ASSERT_EQUALS(iterator->_singleName, "filter"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "filter to apply before inserting"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "drop") { + ASSERT_EQUALS(iterator->_singleName, "drop"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "drop each collection before import"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "oplogReplay") { + ASSERT_EQUALS(iterator->_singleName, "oplogReplay"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "replay oplog for point-in-time restore"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "oplogLimit") { + ASSERT_EQUALS(iterator->_singleName, "oplogLimit"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "include oplog entries before the provided Timestamp (seconds[:ordinal]) during the oplog replay; the ordinal value is optional"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "keepIndexVersion") { + ASSERT_EQUALS(iterator->_singleName, "keepIndexVersion"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "don't upgrade indexes to newest version"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "noOptionsRestore") { + ASSERT_EQUALS(iterator->_singleName, "noOptionsRestore"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "don't restore collection options"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "noIndexRestore") { + ASSERT_EQUALS(iterator->_singleName, "noIndexRestore"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "don't restore indexes"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "w") { + ASSERT_EQUALS(iterator->_singleName, "w"); + ASSERT_EQUALS(iterator->_type, moe::Int); + ASSERT_EQUALS(iterator->_description, "minimum number of replicas per write"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(0); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "dir") { + ASSERT_EQUALS(iterator->_singleName, "dir"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "directory to restore from"); + ASSERT_EQUALS(iterator->_isVisible, false); + moe::Value defaultVal(std::string("dump")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "indexesLast") { + ASSERT_EQUALS(iterator->_singleName, "indexesLast"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "wait to add indexes (now default)"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#ifdef MONGO_SSL + else if (iterator->_dottedName == "ssl") { + ASSERT_EQUALS(iterator->_singleName, "ssl"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "use SSL for all connections"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CAFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCAFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Authority file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyFile") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "PEM certificate/key file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyPassword") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyPassword"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password for key in PEM file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CRLFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCRLFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Revocation List file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.FIPSMode") { + ASSERT_EQUALS(iterator->_singleName, "sslFIPSMode"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "activate FIPS 140-2 mode at startup"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#endif + else { + ::mongo::StringBuilder sb; + sb << "Found extra option: " << iterator->_dottedName << + " which we did not register"; + FAIL(sb.str()); + } + } + } + +} // namespace diff --git a/src/mongo/tools/mongostat_options.cpp b/src/mongo/tools/mongostat_options.cpp index b695dd6606d..89a3b11835e 100644 --- a/src/mongo/tools/mongostat_options.cpp +++ b/src/mongo/tools/mongostat_options.cpp @@ -17,7 +17,6 @@ #include "mongo/tools/mongostat_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 { @@ -164,29 +163,4 @@ namespace mongo { return Status::OK(); } - MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoStatOptions)(InitializerContext* context) { - return addMongoStatOptions(&moe::startupOptions); - } - - MONGO_STARTUP_OPTIONS_VALIDATE(MongoStatOptions)(InitializerContext* context) { - if (handlePreValidationMongoStatOptions(moe::startupOptionsParsed)) { - ::_exit(EXIT_SUCCESS); - } - Status ret = moe::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); - } - - MONGO_STARTUP_OPTIONS_STORE(MongoStatOptions)(InitializerContext* context) { - Status ret = storeMongoStatOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - std::cerr << ret.toString() << std::endl; - std::cerr << "try '" << context->args()[0] << " --help' for more information" - << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); - } } diff --git a/src/mongo/tools/mongostat_options_init.cpp b/src/mongo/tools/mongostat_options_init.cpp new file mode 100644 index 00000000000..e706f397327 --- /dev/null +++ b/src/mongo/tools/mongostat_options_init.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 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/mongostat_options.h" + +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoStatOptions)(InitializerContext* context) { + return addMongoStatOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(MongoStatOptions)(InitializerContext* context) { + if (handlePreValidationMongoStatOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); + } + Status ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(MongoStatOptions)(InitializerContext* context) { + Status ret = storeMongoStatOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); + } +} diff --git a/src/mongo/tools/mongostat_options_test.cpp b/src/mongo/tools/mongostat_options_test.cpp new file mode 100644 index 00000000000..a067162c664 --- /dev/null +++ b/src/mongo/tools/mongostat_options_test.cpp @@ -0,0 +1,342 @@ +/* Copyright 2013 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/tools/mongostat_options.h" + +#include "mongo/bson/util/builder.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace { + + namespace moe = ::mongo::optionenvironment; + + TEST(Registration, RegisterAllOptions) { + + moe::OptionSection options; + + ASSERT_OK(::mongo::addMongoStatOptions(&options)); + + std::vector<moe::OptionDescription> options_vector; + ASSERT_OK(options.getAllOptions(&options_vector)); + + for(std::vector<moe::OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_dottedName == "help") { + ASSERT_EQUALS(iterator->_singleName, "help"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "produce help message"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "verbose") { + ASSERT_EQUALS(iterator->_singleName, "verbose,v"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "be more verbose (include multiple times for more verbosity e.g. -vvvvv)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "quiet") { + ASSERT_EQUALS(iterator->_singleName, "quiet"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "silence all non error diagnostic messages"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "version") { + ASSERT_EQUALS(iterator->_singleName, "version"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "print the program's version and exit"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vv") { + ASSERT_EQUALS(iterator->_singleName, "vv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvv") { + ASSERT_EQUALS(iterator->_singleName, "vvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "host") { + ASSERT_EQUALS(iterator->_singleName, "host,h"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "mongo host to connect to ( <set name>/s1,s2 for sets)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "port") { + ASSERT_EQUALS(iterator->_singleName, "port"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "server port. Can also use --host hostname:port"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ipv6") { + ASSERT_EQUALS(iterator->_singleName, "ipv6"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable IPv6 support (disabled by default)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "username") { + ASSERT_EQUALS(iterator->_singleName, "username,u"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "username"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "password") { + ASSERT_EQUALS(iterator->_singleName, "password,p"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + moe::Value implicitVal(std::string("")); + ASSERT_TRUE(iterator->_implicit.equal(implicitVal)); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationDatabase") { + ASSERT_EQUALS(iterator->_singleName, "authenticationDatabase"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "user source (defaults to dbname)"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationMechanism") { + ASSERT_EQUALS(iterator->_singleName, "authenticationMechanism"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "authentication mechanism"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("MONGODB-CR")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "noheaders") { + ASSERT_EQUALS(iterator->_singleName, "noheaders"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "don't output column names"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "rowcount") { + ASSERT_EQUALS(iterator->_singleName, "rowcount,n"); + ASSERT_EQUALS(iterator->_type, moe::Int); + ASSERT_EQUALS(iterator->_description, "number of stats lines to print (0 for indefinite)"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(0); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "http") { + ASSERT_EQUALS(iterator->_singleName, "http"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "use http instead of raw db connection"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "discover") { + ASSERT_EQUALS(iterator->_singleName, "discover"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "discover nodes and display stats for all"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "all") { + ASSERT_EQUALS(iterator->_singleName, "all"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "all optional fields"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "sleep") { + ASSERT_EQUALS(iterator->_singleName, "sleep"); + ASSERT_EQUALS(iterator->_type, moe::Int); + ASSERT_EQUALS(iterator->_description, "hidden description"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#ifdef MONGO_SSL + else if (iterator->_dottedName == "ssl") { + ASSERT_EQUALS(iterator->_singleName, "ssl"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "use SSL for all connections"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CAFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCAFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Authority file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyFile") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "PEM certificate/key file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyPassword") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyPassword"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password for key in PEM file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CRLFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCRLFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Revocation List file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.FIPSMode") { + ASSERT_EQUALS(iterator->_singleName, "sslFIPSMode"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "activate FIPS 140-2 mode at startup"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#endif + else { + ::mongo::StringBuilder sb; + sb << "Found extra option: " << iterator->_dottedName << + " which we did not register"; + FAIL(sb.str()); + } + } + } + +} // namespace diff --git a/src/mongo/tools/mongotop_options.cpp b/src/mongo/tools/mongotop_options.cpp index 09af7f47b10..83b9da1320d 100644 --- a/src/mongo/tools/mongotop_options.cpp +++ b/src/mongo/tools/mongotop_options.cpp @@ -17,7 +17,6 @@ #include "mongo/tools/mongotop_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 { @@ -84,29 +83,4 @@ namespace mongo { return Status::OK(); } - MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoTopOptions)(InitializerContext* context) { - return addMongoTopOptions(&moe::startupOptions); - } - - MONGO_STARTUP_OPTIONS_VALIDATE(MongoTopOptions)(InitializerContext* context) { - if (handlePreValidationMongoTopOptions(moe::startupOptionsParsed)) { - ::_exit(EXIT_SUCCESS); - } - Status ret = moe::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); - } - - MONGO_STARTUP_OPTIONS_STORE(MongoTopOptions)(InitializerContext* context) { - Status ret = storeMongoTopOptions(moe::startupOptionsParsed, context->args()); - if (!ret.isOK()) { - std::cerr << ret.toString() << std::endl; - std::cerr << "try '" << context->args()[0] << " --help' for more information" - << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - return Status::OK(); - } } diff --git a/src/mongo/tools/mongotop_options_init.cpp b/src/mongo/tools/mongotop_options_init.cpp new file mode 100644 index 00000000000..7b4c9961444 --- /dev/null +++ b/src/mongo/tools/mongotop_options_init.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 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/mongotop_options.h" + +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace mongo { + MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongoTopOptions)(InitializerContext* context) { + return addMongoTopOptions(&moe::startupOptions); + } + + MONGO_STARTUP_OPTIONS_VALIDATE(MongoTopOptions)(InitializerContext* context) { + if (handlePreValidationMongoTopOptions(moe::startupOptionsParsed)) { + ::_exit(EXIT_SUCCESS); + } + Status ret = moe::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + } + + MONGO_STARTUP_OPTIONS_STORE(MongoTopOptions)(InitializerContext* context) { + Status ret = storeMongoTopOptions(moe::startupOptionsParsed, context->args()); + if (!ret.isOK()) { + std::cerr << ret.toString() << std::endl; + std::cerr << "try '" << context->args()[0] << " --help' for more information" + << std::endl; + ::_exit(EXIT_BADOPTIONS); + } + return Status::OK(); + } +} diff --git a/src/mongo/tools/mongotop_options_test.cpp b/src/mongo/tools/mongotop_options_test.cpp new file mode 100644 index 00000000000..55af3e319e5 --- /dev/null +++ b/src/mongo/tools/mongotop_options_test.cpp @@ -0,0 +1,305 @@ +/* Copyright 2013 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mongo/tools/mongotop_options.h" + +#include "mongo/bson/util/builder.h" +#include "mongo/unittest/unittest.h" +#include "mongo/util/options_parser/options_parser.h" +#include "mongo/util/options_parser/startup_options.h" + +namespace { + + namespace moe = ::mongo::optionenvironment; + + TEST(Registration, RegisterAllOptions) { + + moe::OptionSection options; + + ASSERT_OK(::mongo::addMongoTopOptions(&options)); + + std::vector<moe::OptionDescription> options_vector; + ASSERT_OK(options.getAllOptions(&options_vector)); + + for(std::vector<moe::OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_dottedName == "help") { + ASSERT_EQUALS(iterator->_singleName, "help"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "produce help message"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "verbose") { + ASSERT_EQUALS(iterator->_singleName, "verbose,v"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "be more verbose (include multiple times for more verbosity e.g. -vvvvv)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "quiet") { + ASSERT_EQUALS(iterator->_singleName, "quiet"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "silence all non error diagnostic messages"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "version") { + ASSERT_EQUALS(iterator->_singleName, "version"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "print the program's version and exit"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vv") { + ASSERT_EQUALS(iterator->_singleName, "vv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvv") { + ASSERT_EQUALS(iterator->_singleName, "vvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "vvvvvvvvvv") { + ASSERT_EQUALS(iterator->_singleName, "vvvvvvvvvv"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "verbose"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "host") { + ASSERT_EQUALS(iterator->_singleName, "host,h"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "mongo host to connect to ( <set name>/s1,s2 for sets)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "port") { + ASSERT_EQUALS(iterator->_singleName, "port"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "server port. Can also use --host hostname:port"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ipv6") { + ASSERT_EQUALS(iterator->_singleName, "ipv6"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "enable IPv6 support (disabled by default)"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "username") { + ASSERT_EQUALS(iterator->_singleName, "username,u"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "username"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "password") { + ASSERT_EQUALS(iterator->_singleName, "password,p"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + moe::Value implicitVal(std::string("")); + ASSERT_TRUE(iterator->_implicit.equal(implicitVal)); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationDatabase") { + ASSERT_EQUALS(iterator->_singleName, "authenticationDatabase"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "user source (defaults to dbname)"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "authenticationMechanism") { + ASSERT_EQUALS(iterator->_singleName, "authenticationMechanism"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "authentication mechanism"); + ASSERT_EQUALS(iterator->_isVisible, true); + moe::Value defaultVal(std::string("MONGODB-CR")); + ASSERT_TRUE(iterator->_default.equal(defaultVal)); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "locks") { + ASSERT_EQUALS(iterator->_singleName, "locks"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "use db lock info instead of top"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "sleep") { + ASSERT_EQUALS(iterator->_singleName, "sleep"); + ASSERT_EQUALS(iterator->_type, moe::Int); + ASSERT_EQUALS(iterator->_description, "hidden description"); + ASSERT_EQUALS(iterator->_isVisible, false); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#ifdef MONGO_SSL + else if (iterator->_dottedName == "ssl") { + ASSERT_EQUALS(iterator->_singleName, "ssl"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "use SSL for all connections"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CAFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCAFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Authority file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyFile") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "PEM certificate/key file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.PEMKeyPassword") { + ASSERT_EQUALS(iterator->_singleName, "sslPEMKeyPassword"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "password for key in PEM file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.CRLFile") { + ASSERT_EQUALS(iterator->_singleName, "sslCRLFile"); + ASSERT_EQUALS(iterator->_type, moe::String); + ASSERT_EQUALS(iterator->_description, "Certificate Revocation List file for SSL"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } + else if (iterator->_dottedName == "ssl.FIPSMode") { + ASSERT_EQUALS(iterator->_singleName, "sslFIPSMode"); + ASSERT_EQUALS(iterator->_type, moe::Switch); + ASSERT_EQUALS(iterator->_description, "activate FIPS 140-2 mode at startup"); + ASSERT_EQUALS(iterator->_isVisible, true); + ASSERT_TRUE(iterator->_default.isEmpty()); + ASSERT_TRUE(iterator->_implicit.isEmpty()); + ASSERT_EQUALS(iterator->_isComposing, false); + } +#endif + else { + ::mongo::StringBuilder sb; + sb << "Found extra option: " << iterator->_dottedName << + " which we did not register"; + FAIL(sb.str()); + } + } + } + +} // namespace |