soothe_client/
verbosity.rs1pub const VERBOSITY_QUIET: &str = "quiet";
5pub const VERBOSITY_NORMAL: &str = "normal";
7pub const VERBOSITY_DEBUG: &str = "debug";
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
12#[repr(u8)]
13pub enum VerbosityTier {
14 Quiet = 0,
16 Normal = 1,
18 Detailed = 2,
20 Debug = 3,
22 Internal = 99,
24}
25
26fn verbosity_level_value(verbosity: &str) -> i32 {
27 match verbosity {
28 VERBOSITY_QUIET => 0,
29 VERBOSITY_NORMAL => 1,
30 VERBOSITY_DEBUG => 3,
31 _ => 1,
32 }
33}
34
35pub fn should_show(tier: VerbosityTier, verbosity: &str) -> bool {
37 if tier == VerbosityTier::Internal {
38 return false;
39 }
40 (tier as i32) <= verbosity_level_value(verbosity)
41}
42
43pub fn is_valid_verbosity_level(s: &str) -> bool {
45 matches!(s, VERBOSITY_QUIET | VERBOSITY_NORMAL | VERBOSITY_DEBUG)
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn quiet_always_shows_quiet_tier() {
54 assert!(should_show(VerbosityTier::Quiet, VERBOSITY_QUIET));
55 assert!(!should_show(VerbosityTier::Normal, VERBOSITY_QUIET));
56 }
57
58 #[test]
59 fn internal_never_shows() {
60 assert!(!should_show(VerbosityTier::Internal, VERBOSITY_DEBUG));
61 }
62
63 #[test]
64 fn valid_levels() {
65 assert!(is_valid_verbosity_level("normal"));
66 assert!(!is_valid_verbosity_level("loud"));
67 }
68}