diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 42 | ||||
-rw-r--r-- | src/main.rs | 5 |
2 files changed, 9 insertions, 38 deletions
diff --git a/src/config.rs b/src/config.rs index 0fc313f..ec4cebd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,7 +1,6 @@ use std::path::PathBuf; use clap::{Args, Parser}; -use tracing::{metadata::LevelFilter, Level}; #[derive(Debug, Clone, Default, Parser)] #[command(author, version, about)] @@ -25,8 +24,11 @@ pub struct Config { #[arg(short = 'P', long = "project")] pub include: Vec<PathBuf>, - #[command(flatten)] - pub verbosity: Verbosity, + /// Print additional information per occurrence. + /// + /// Conflicts with `--quiet`. + #[arg(short, long, global = true, action = clap::ArgAction::Count)] + pub verbosity: u8, } #[derive(Debug, Default, Clone, Args)] @@ -88,37 +90,3 @@ pub struct Projects { #[arg(long, short)] pub tmux: bool, } - -#[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<Level> { - 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::<Level>::from(value).into() - } -} diff --git a/src/main.rs b/src/main.rs index 25a051e..103101b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,9 @@ +use std::str::FromStr; + use anyhow::Result; use clap::Parser; use projectr::{config::Config, project::Projects, tmux::Tmux, Search}; +use tracing::metadata::LevelFilter; fn main() -> Result<()> { let config = Config::parse(); @@ -8,7 +11,7 @@ fn main() -> Result<()> { tracing_subscriber::fmt::fmt() .pretty() .with_writer(std::io::stderr) - .with_max_level(&config.verbosity) + .with_max_level(LevelFilter::from_str(&config.verbosity.to_string())?) .init(); let mut projects = Projects::from(config.parsers); |