summaryrefslogtreecommitdiff
path: root/src/mongo/util/options_parser/environment.cpp
diff options
context:
space:
mode:
authorShaun Verch <shaun.verch@10gen.com>2013-08-25 21:37:26 -0700
committerShaun Verch <shaun.verch@10gen.com>2013-09-05 13:49:34 -0400
commit98b224b13cbd868745864a8817a60b801144872f (patch)
tree63ed07a619b6c26a2634c26b5aedbad5a7762a38 /src/mongo/util/options_parser/environment.cpp
parent9c9f50ea6b89547c3150e0876f74366b3fba080f (diff)
downloadmongo-98b224b13cbd868745864a8817a60b801144872f.tar.gz
SERVER-8510 Add function to extract only explicitly set values from Environment
Diffstat (limited to 'src/mongo/util/options_parser/environment.cpp')
-rw-r--r--src/mongo/util/options_parser/environment.cpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/mongo/util/options_parser/environment.cpp b/src/mongo/util/options_parser/environment.cpp
index 7a2e33bfd06..41e94d90d40 100644
--- a/src/mongo/util/options_parser/environment.cpp
+++ b/src/mongo/util/options_parser/environment.cpp
@@ -41,14 +41,15 @@ namespace optionenvironment {
typedef std::map<Key, Value>::const_iterator it_type;
it_type value = values.find(get_key);
if (value == values.end()) {
- StringBuilder sb;
- sb << "Value not found for key: " << get_key;
- return Status(ErrorCodes::NoSuchKey, sb.str());
- }
- else {
- *get_value = value->second;
- return Status::OK();
+ value = default_values.find(get_key);
+ if (value == default_values.end()) {
+ StringBuilder sb;
+ sb << "Value not found for key: " << get_key;
+ return Status(ErrorCodes::NoSuchKey, sb.str());
+ }
}
+ *get_value = value->second;
+ return Status::OK();
}
/** Set the Value in our Environment. Always disallow empty values */
@@ -78,6 +79,26 @@ namespace optionenvironment {
return Status::OK();
}
+ /** Set the default Value for the given Key in our Environment. Always disallow empty values */
+ Status Environment::setDefault(const Key& add_key, const Value& add_value) {
+
+ // 1. Make sure value is not empty
+ if (add_value.isEmpty()) {
+ return Status(ErrorCodes::InternalError, "Attempted to set an empty default value");
+ }
+
+ // 2. Disallow modifying defaults after calling validate on this Environment
+ if (valid) {
+ return Status(ErrorCodes::InternalError,
+ "Attempted to set a default value after calling validate");
+ }
+
+ // 3. Add this value to our defaults
+ default_values[add_key] = add_value;
+
+ return Status::OK();
+ }
+
/** Set all the Values from the source Environment in our Environment. Does not check for empty
* values as the source Environment should not have been allowed to have any */
Status Environment::setAll(const Environment& add_environment) {