Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: verbosity cli args #1574

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions packages/nextclade-cli/src/cli/verbosity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,36 @@ pub struct Verbosity {

impl Verbosity {
pub const fn get_filter_level(&self) -> LevelFilter {
// --verbosity=<level> and --silent take priority over -v and -q
if self.silent {
// --verbosity=<level> and --silent take priority over -v and -q
LevelFilter::Off
} else {
self.verbosity
let ilevel = level_to_int(self.verbosity);
let ilevel = ilevel.saturating_add(self.verbose);
let ilevel = ilevel.saturating_sub(self.quiet);
level_from_int(ilevel)
}
}
}

const fn level_to_int(level: LevelFilter) -> u8 {
match level {
LevelFilter::Off => 0,
LevelFilter::Error => 1,
LevelFilter::Warn => 2,
LevelFilter::Info => 3,
LevelFilter::Debug => 4,
LevelFilter::Trace => 5,
}
}

const fn level_from_int(verbosity: u8) -> LevelFilter {
match verbosity {
0 => LevelFilter::Off,
1 => LevelFilter::Error,
2 => LevelFilter::Warn,
3 => LevelFilter::Info,
4 => LevelFilter::Debug,
5.. => LevelFilter::Trace,
}
}