mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
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:
committed by
Jan Höppner
parent
03b73ab3f9
commit
19a5af8da9
@@ -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 {
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user