From 19a5af8da9748801c8aee18b4a8ed6f537d72ca5 Mon Sep 17 00:00:00 2001 From: Steffen Eiden Date: Thu, 21 May 2026 15:12:39 +0200 Subject: [PATCH] rust/utils: Add functions to combine I/O arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add functions to properly parse required and optional input/output parameters that have to be combined into one. Reviewed-by: Jan Höppner Signed-off-by: Steffen Eiden Signed-off-by: Jan Höppner --- rust/utils/src/cli.rs | 23 +++++++++++++++++++++++ rust/utils/src/lib.rs | 5 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/rust/utils/src/cli.rs b/rust/utils/src/cli.rs index 066e939f..84ed84f1 100644 --- a/rust/utils/src/cli.rs +++ b/rust/utils/src/cli.rs @@ -276,6 +276,29 @@ impl DeprecatedVerbosityOptions { ) } } +pub fn combined_path_opt<'a, N: AsRef, P: AsRef>( + named: &'a Option, + positional: &'a Option

, + default: &'a str, +) -> &'a str { + match (named, positional) { + (None, Some(i)) => i.as_ref(), + (Some(i), None) => i.as_ref(), + (Some(_), Some(_)) => unreachable!(), + (None, None) => default, + } +} +pub fn combined_path_req<'a, N: AsRef, P: AsRef>( + named: &'a Option, + positional: &'a Option

, +) -> &'a str { + match (named, positional) { + (None, Some(i)) => i.as_ref(), + (Some(i), None) => i.as_ref(), + (Some(_), Some(_)) => unreachable!(), + (None, None) => unreachable!(), + } +} #[cfg(test)] mod test { diff --git a/rust/utils/src/lib.rs b/rust/utils/src/lib.rs index 1efec7c8..8af368ee 100644 --- a/rust/utils/src/lib.rs +++ b/rust/utils/src/lib.rs @@ -16,8 +16,9 @@ pub use ::log::LevelFilter; pub use crate::{ cli::{ - get_reader_from_cli_file_arg, get_writer_from_cli_file_arg, print_cli_error, print_error, - CertificateOptions, DeprecatedVerbosityOptions, VerbosityOptions, STDIN, STDOUT, + combined_path_opt, combined_path_req, get_reader_from_cli_file_arg, + get_writer_from_cli_file_arg, print_cli_error, print_error, CertificateOptions, + DeprecatedVerbosityOptions, VerbosityOptions, STDIN, STDOUT, }, exit_code::{docstring, ExitCodeDoc, ExitCodeTrait, ExitCodeVariantDoc}, file::{AtomicFile, AtomicFileOperation},