use clap::{command, ArgAction, Args};
use tracing::{level_filters::LevelFilter, Level};
use tracing_subscriber::filter::Directive;
#[derive(Debug, Copy, Clone, Args)]
#[command(next_help_heading = "Display")]
pub struct Verbosity {
#[clap(short, long, action = ArgAction::Count, global = true, default_value_t = 3, verbatim_doc_comment, help_heading = "Display")]
verbosity: u8,
#[clap(long, alias = "silent", global = true, help_heading = "Display")]
quiet: bool,
}
impl Verbosity {
pub fn directive(&self) -> Directive {
if self.quiet {
LevelFilter::OFF.into()
} else {
let level = match self.verbosity - 1 {
0 => Level::ERROR,
1 => Level::WARN,
2 => Level::INFO,
3 => Level::DEBUG,
_ => Level::TRACE,
};
format!("{level}").parse().unwrap()
}
}
}