diff --git a/Cargo.lock b/Cargo.lock index 607ae75..96ed176 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,6 +228,16 @@ dependencies = [ "clap_derive", ] +[[package]] +name = "clap-verbosity-flag" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb9b20c0dd58e4c2e991c8d203bbeb76c11304d1011659686b5b644bc29aa478" +dependencies = [ + "clap", + "log", +] + [[package]] name = "clap_builder" version = "4.5.1" @@ -800,6 +810,7 @@ name = "riptide-shell" version = "0.2.0" dependencies = [ "clap", + "clap-verbosity-flag", "directories", "exitcode", "log", diff --git a/shell/Cargo.toml b/shell/Cargo.toml index a38f6f2..8900212 100644 --- a/shell/Cargo.toml +++ b/shell/Cargo.toml @@ -7,6 +7,7 @@ license.workspace = true edition.workspace = true [dependencies] +clap-verbosity-flag = "2" directories.workspace = true exitcode = "1.1" owo-colors = "4" diff --git a/shell/src/main.rs b/shell/src/main.rs index 772fb50..efeee67 100644 --- a/shell/src/main.rs +++ b/shell/src/main.rs @@ -37,8 +37,8 @@ struct Options { login: bool, /// Set the verbosity level - #[arg(short = 'v', long = "verbose", action = clap::ArgAction::Count)] - verbosity: u8, + #[command(flatten)] + verbose: clap_verbosity_flag::Verbosity, /// Silence all output #[arg(short = 'q', long = "quiet")] @@ -52,25 +52,10 @@ struct Options { /// In private mode, session history is kept independent from other sessions /// and is stored only in memory. All history generated during a private /// session will be forgotten when the session terminates. - #[structopt(long = "private")] + #[arg(long = "private")] private: bool, } -impl Options { - fn log_level_filter(&self) -> log::LevelFilter { - if self.quiet { - log::LevelFilter::Off - } else { - match self.verbosity { - 0 => log::LevelFilter::Warn, - 1 => log::LevelFilter::Info, - 2 => log::LevelFilter::Debug, - _ => log::LevelFilter::Trace, - } - } - } -} - /// Entrypoint of the program. This just does some boring setup and teardown /// around the real main body of the program. fn main() { @@ -78,7 +63,7 @@ fn main() { let options = Options::parse(); // Initialize logging. - logger::init(options.log_level_filter()); + logger::init(options.verbose.log_level_filter()); log_panics::init(); // Create a single-threaded Tokio runtime, which drives the async Riptide