use clap::{Args, Parser}; use tracing::{metadata::LevelFilter, Level}; use crate::search::Search; /// Tool for listing project directories. #[derive(Debug, Clone, Default, Parser)] #[command(author, version, about)] pub struct Config { #[command(flatten)] pub search: Search, #[command(flatten)] pub verbosity: Verbosity, } #[derive(Debug, Default, Clone, Args)] pub struct Verbosity { /// Print additional information per occurrence. /// /// Conflicts with `--quiet`. #[arg(short, long, global = true, action = clap::ArgAction::Count, conflicts_with = "quiet")] pub verbose: u8, /// Suppress all output. /// /// Conflicts with `--verbose`. #[arg(short, long, global = true, conflicts_with = "verbose")] pub quiet: bool, } impl From<&Verbosity> for Option { fn from(value: &Verbosity) -> Self { match 1 + value.verbose - u8::from(value.quiet) { 0 => None, 1 => Some(Level::ERROR), 2 => Some(Level::WARN), 3 => Some(Level::INFO), 4 => Some(Level::DEBUG), _ => Some(Level::TRACE), } } } impl From<&Verbosity> for LevelFilter { fn from(value: &Verbosity) -> Self { Option::::from(value).into() } }