diff --git a/option_parser/src/lib.rs b/option_parser/src/lib.rs index 6be4bcbb1..cd7bbd488 100644 --- a/option_parser/src/lib.rs +++ b/option_parser/src/lib.rs @@ -226,6 +226,17 @@ impl OptionParser { self } + /// Registers multiple flag-style options that do not take a value. + /// + /// Equivalent to calling [`add_valueless`](Self::add_valueless) for each + /// element in the slice. + pub fn add_all_valueless(&mut self, options: &[&str]) -> &mut Self { + for option in options { + self.add_valueless(option); + } + self + } + /// Returns the raw string value of an option, or `None` if the option was /// not set or if its value is an empty string (e.g. `key=`). /// diff --git a/vmm/src/config.rs b/vmm/src/config.rs index b3a35c8f8..d680c23d3 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -2141,10 +2141,7 @@ impl ConsoleConfig { pub fn parse(console: &str) -> Result { let mut parser = OptionParser::new(); parser - .add_valueless("off") - .add_valueless("pty") - .add_valueless("tty") - .add_valueless("null") + .add_all_valueless(&["off", "pty", "tty", "null"]) .add("file") .add("iommu") .add("socket");