mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
+5
-2
@@ -132,7 +132,10 @@ impl OptionParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, option: &str) -> Option<String> {
|
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 {
|
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>> {
|
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),
|
None => Ok(None),
|
||||||
Some(v) => Ok(Some(v.parse().map_err(|_| {
|
Some(v) => Ok(Some(v.parse().map_err(|_| {
|
||||||
OptionParserError::Conversion(option.to_owned(), v.to_owned())
|
OptionParserError::Conversion(option.to_owned(), v.to_owned())
|
||||||
|
|||||||
Reference in New Issue
Block a user