* Interpret settings value based on registered flags. * * @param[in] key key information to know if key was negated * @param[in] value string value of setting to be parsed * @param[in] flags ArgsManager registered argument flags * @param[out] error Error description if settings value is not valid * * @return parsed settings value if it is valid, otherwise nullopt accomp
| 103 | * by a descriptive error string |
| 104 | */ |
| 105 | std::optional<common::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value, |
| 106 | unsigned int flags, std::string& error) |
| 107 | { |
| 108 | // Return negated settings as false values. |
| 109 | if (key.negated) { |
| 110 | if (flags & ArgsManager::DISALLOW_NEGATION) { |
| 111 | error = strprintf("Negating of -%s is meaningless and therefore forbidden", key.name); |
| 112 | return std::nullopt; |
| 113 | } |
| 114 | // Double negatives like -nofoo=0 are supported (but discouraged) |
| 115 | if (value && !InterpretBool(*value)) { |
| 116 | LogWarning("Parsed potentially confusing double-negative -%s=%s", key.name, *value); |
| 117 | return true; |
| 118 | } |
| 119 | return false; |
| 120 | } |
| 121 | if (!value && (flags & ArgsManager::DISALLOW_ELISION)) { |
| 122 | error = strprintf("Can not set -%s with no value. Please specify value with -%s=value.", key.name, key.name); |
| 123 | return std::nullopt; |
| 124 | } |
| 125 | return value ? *value : ""; |
| 126 | } |
| 127 | |
| 128 | // Define default constructor and destructor that are not inline, so code instantiating this class doesn't need to |
| 129 | // #include class definitions for all members. |
no test coverage detected