option_parser: add add_all_valueless() helper

Helpful to prevent repetitions.

On-behalf-of: Philipp Schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
This commit is contained in:
Philipp Schuster
2026-05-11 15:42:47 +02:00
committed by Rob Bradford
parent fcfae4cc4b
commit a56f49787c
2 changed files with 12 additions and 4 deletions

View File

@@ -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=`).
///

View File

@@ -2141,10 +2141,7 @@ impl ConsoleConfig {
pub fn parse(console: &str) -> Result<Self> {
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");