From a56f49787c0d0be7c41a862826e2d2d9005414ca Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Mon, 11 May 2026 15:42:47 +0200 Subject: [PATCH] option_parser: add `add_all_valueless()` helper Helpful to prevent repetitions. On-behalf-of: Philipp Schuster@sap.com Signed-off-by: Philipp Schuster --- option_parser/src/lib.rs | 11 +++++++++++ vmm/src/config.rs | 5 +---- 2 files changed, 12 insertions(+), 4 deletions(-) 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");