mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
option_parser: Extend option parsing for lists
While parsing each parameter for getting the list of option/value, we check if the value is a list separated between brackets. If that's the case, we reconstruct the list so that it can be parsed afterwards, even though it uses commas for separating each value. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
d3b2f2a4d9
commit
184a3d1fb5
@ -49,7 +49,26 @@ impl OptionParser {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let options_list: Vec<&str> = input.trim().split(',').collect();
|
||||
let mut options_list: Vec<String> = Vec::new();
|
||||
let mut merge_elements = false;
|
||||
for element in input.trim().split(',') {
|
||||
if merge_elements {
|
||||
if let Some(last) = options_list.last_mut() {
|
||||
*last = format!("{},{}", last, element);
|
||||
} else {
|
||||
return Err(OptionParserError::InvalidSyntax(input.to_owned()));
|
||||
}
|
||||
} else {
|
||||
options_list.push(element.to_string());
|
||||
}
|
||||
|
||||
if element.contains('[') {
|
||||
merge_elements = true;
|
||||
}
|
||||
if element.contains(']') {
|
||||
merge_elements = false;
|
||||
}
|
||||
}
|
||||
|
||||
for option in options_list.iter() {
|
||||
let parts: Vec<&str> = option.split('=').collect();
|
||||
|
Loading…
Reference in New Issue
Block a user