vmm: config: Accept empty value strings

The integration tests and documentation make use of empty value strings
like "--net tap=" accept them but return None so that the default value
will be used as expected.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-04-01 09:46:16 +01:00
parent 218c780f67
commit 057e71d266

View File

@ -132,7 +132,10 @@ impl OptionParser {
}
pub fn get(&self, option: &str) -> Option<String> {
self.options.get(option).and_then(|v| v.value.clone())
self.options
.get(option)
.and_then(|v| v.value.clone())
.and_then(|s| if s.is_empty() { None } else { Some(s) })
}
pub fn is_set(&self, option: &str) -> bool {
@ -143,7 +146,7 @@ impl OptionParser {
}
pub fn convert<T: FromStr>(&self, option: &str) -> OptionParserResult<Option<T>> {
match self.options.get(option).and_then(|v| v.value.as_ref()) {
match self.get(option) {
None => Ok(None),
Some(v) => Ok(Some(v.parse().map_err(|_| {
OptionParserError::Conversion(option.to_owned(), v.to_owned())