rust: Streamline and cleanup verbosity handling

Create one implementation for the verbose option to be used by all
tools. While at it, add a quiet option to decrease the verbosity.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Steffen Eiden
2024-11-07 11:03:41 +01:00
parent 576a230341
commit 53d803abf3
9 changed files with 125 additions and 123 deletions
+20 -10
View File
@@ -8,13 +8,14 @@ mod hexslice;
mod log;
mod tmpfile;
pub use crate::cli::CertificateOptions;
pub use crate::cli::{get_reader_from_cli_file_arg, get_writer_from_cli_file_arg};
pub use crate::cli::{print_cli_error, print_error};
pub use crate::cli::{CertificateOptions, DeprecatedVerbosityOptions, VerbosityOptions};
pub use crate::cli::{STDIN, STDOUT};
pub use crate::hexslice::HexSlice;
pub use crate::log::PvLogger;
pub use crate::tmpfile::TemporaryDirectory;
pub use ::log::LevelFilter;
/// Get the s390-tools release string
///
@@ -41,23 +42,18 @@ macro_rules! release_string {
}
#[macro_export]
/// Print the version to stdout
///
/// verbosity: integer if >0 more and more details printed
/// feat: (optional) list of features
/// rel_str: a string containig the release name
macro_rules! print_version {
($verbosity: expr, $year: expr $( ,$feat: expr)?) => {{
macro_rules! __print_version {
($year: expr, $verbosity: expr $( ,$feat: expr)?) => {{
println!(
"{} version {}\nCopyright IBM Corp. {}",
env!("CARGO_PKG_NAME"),
$crate::release_string!(),
$year,
);
if $verbosity > 0 {
if $verbosity > $crate::LevelFilter::Warn {
$($feat.iter().for_each(|f| print!("{f} ")); println!("(compiled)");)?
}
if $verbosity > 1 {
if $verbosity > $crate::LevelFilter::Info {
println!(
"\n{}-crate {}",
env!("CARGO_PKG_NAME"),
@@ -67,6 +63,20 @@ macro_rules! print_version {
}};
}
#[macro_export]
/// Print the version to stdout
///
/// `verbosity` (optional): `LogLevel`
/// `feat` (optional): list of features
/// `rel_str`: a string containig the release name
macro_rules! print_version {
($year: expr $( ;$feat: expr)?) => {
$crate::__print_version!($year, $crate::LevelFilter::Warn $(, $feat)*)
};
($year: expr, $verbosity: expr $( ;$feat: expr)?) => {
$crate::__print_version!($year, $verbosity $(, $feat)*)
};
}
/// Asserts a constant expression evaluates to `true`.
///
/// If the expression is not evaluated to `true` the compilation will fail.