pub const VERBOSITY_QUIET: &str = "quiet";
pub const VERBOSITY_NORMAL: &str = "normal";
pub const VERBOSITY_DEBUG: &str = "debug";
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
pub enum VerbosityTier {
Quiet = 0,
Normal = 1,
Detailed = 2,
Debug = 3,
Internal = 99,
}
fn verbosity_level_value(verbosity: &str) -> i32 {
match verbosity {
VERBOSITY_QUIET => 0,
VERBOSITY_NORMAL => 1,
VERBOSITY_DEBUG => 3,
_ => 1,
}
}
pub fn should_show(tier: VerbosityTier, verbosity: &str) -> bool {
if tier == VerbosityTier::Internal {
return false;
}
(tier as i32) <= verbosity_level_value(verbosity)
}
pub fn is_valid_verbosity_level(s: &str) -> bool {
matches!(s, VERBOSITY_QUIET | VERBOSITY_NORMAL | VERBOSITY_DEBUG)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn quiet_always_shows_quiet_tier() {
assert!(should_show(VerbosityTier::Quiet, VERBOSITY_QUIET));
assert!(!should_show(VerbosityTier::Normal, VERBOSITY_QUIET));
}
#[test]
fn internal_never_shows() {
assert!(!should_show(VerbosityTier::Internal, VERBOSITY_DEBUG));
}
#[test]
fn valid_levels() {
assert!(is_valid_verbosity_level("normal"));
assert!(!is_valid_verbosity_level("loud"));
}
}