rust/utils: Add functions to combine I/O arguments

Add functions to properly parse required and optional input/output
parameters that have to be combined into one.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Steffen Eiden
2026-05-21 15:12:39 +02:00
committed by Jan Höppner
parent 03b73ab3f9
commit 19a5af8da9
2 changed files with 26 additions and 2 deletions

View File

@@ -276,6 +276,29 @@ impl DeprecatedVerbosityOptions {
)
}
}
pub fn combined_path_opt<'a, N: AsRef<str>, P: AsRef<str>>(
named: &'a Option<N>,
positional: &'a Option<P>,
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<str>, P: AsRef<str>>(
named: &'a Option<N>,
positional: &'a Option<P>,
) -> &'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 {

View File

@@ -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},