Compare commits

...

2 commits

Author SHA1 Message Date
673eb691e9 fix(cli): clap count parser only works with u8, so revert the change to i8 back
Some checks failed
cargo devel CI / cargo CI (push) Failing after 1m46s
2024-07-09 19:34:46 +02:00
b382b3e501 refactor(cli): cli example was weird 2024-07-09 19:29:20 +02:00
2 changed files with 6 additions and 16 deletions

View file

@ -23,17 +23,7 @@ struct Cli {
fn main() { fn main() {
let cli = Cli::parse(); let cli = Cli::parse();
let _logger = { let _logger = Logger::builder().set_level(cli.verbosity.level()).build();
let mut this = {
let mut this = Logger::builder();
let max_level = cli.verbosity.level();
this.max_level = max_level;
this
};
this.show_time = false;
this
}
.build();
debug!("logger initialized with level: {}", cli.verbosity.level()); debug!("logger initialized with level: {}", cli.verbosity.level());

View file

@ -101,12 +101,12 @@ pub struct VerbosityLevel {
#[arg( #[arg(
long, long,
short = 'v', short = 'v',
action = clap::ArgAction::Count, action = clap::ArgAction::Count, // NOTE: this forces u8 type for some reason
global = true, global = true,
// help = L::verbose_help(), // help = L::verbose_help(),
// long_help = L::verbose_long_help(), // long_help = L::verbose_long_help(),
)] )]
verbose: i8, verbose: u8,
/// make the output less verbose /// make the output less verbose
/// ///
@ -118,7 +118,7 @@ pub struct VerbosityLevel {
global = true, global = true,
conflicts_with = "verbose", conflicts_with = "verbose",
)] )]
quiet: i8, quiet: u8,
} }
impl VerbosityLevel { impl VerbosityLevel {
@ -131,7 +131,7 @@ impl VerbosityLevel {
} }
#[inline] #[inline]
#[must_use] #[must_use]
fn value(&self) -> i8 { fn value(&self) -> u8 {
Self::level_value(Level::INFO) Self::level_value(Level::INFO)
.saturating_sub((self.quiet).min(10)) .saturating_sub((self.quiet).min(10))
.saturating_add((self.verbose).min(10)) .saturating_add((self.verbose).min(10))
@ -189,7 +189,7 @@ impl VerbosityLevel {
#[inline] #[inline]
#[must_use] #[must_use]
const fn level_value(level: Level) -> i8 { const fn level_value(level: Level) -> u8 {
match level { match level {
Level::TRACE => 4, Level::TRACE => 4,
Level::DEBUG => 3, Level::DEBUG => 3,