use clap::{Args, Parser}; use std::path::PathBuf; use tracing_subscriber::{filter::LevelFilter, Layer, Registry}; /// Simple program to manage projects and ssh hosts using tmux #[derive(Parser, Debug)] #[command(author, version, about)] pub struct Cli { /// Path to search recursively for directories pub(crate) path: Vec, /// Add additional directory to search results. Can be specified multiple times #[arg(short, long)] pub(crate) directory: Vec, #[command(flatten)] pub verbose: Verbosity, /// Allows traversal into hidden directories when searching #[arg(long)] pub(crate) hidden: bool, /// Connect to ssh host #[arg(short, long)] pub ssh: Option, } impl Cli { pub fn as_layer(&self) -> Vec + Send + Sync>> { let fmt_layer = tracing_subscriber::fmt::layer() .pretty() .with_filter(self.verbose.as_filter()) .boxed(); vec![fmt_layer] } // TODO: replace this with `impl Figment for Cli` pub fn as_config(&self) -> crate::directories::Config { crate::directories::Config { search: self.path.to_owned(), add: self.directory.to_owned(), hidden: self.hidden, } } } #[derive(Debug, Default, Args)] pub struct Verbosity { /// Print additional information per occurrence #[arg(short, long, action = clap::ArgAction::Count, conflicts_with = "quiet")] pub verbose: u8, /// Suppress all output #[arg(short, long, global = true, conflicts_with = "verbose")] pub quiet: bool, } impl Verbosity { pub fn as_filter(&self) -> LevelFilter { self.into() } } impl From<&Verbosity> for LevelFilter { fn from(value: &Verbosity) -> Self { match value.verbose + 1 - u8::from(value.quiet) { 0 => LevelFilter::OFF, 1 => LevelFilter::ERROR, 2 => LevelFilter::WARN, 3 => LevelFilter::INFO, 4 => LevelFilter::DEBUG, _ => LevelFilter::TRACE, } } } #[cfg(test)] mod tests { #[test] fn test_start() { assert_eq!(1, 1); } }