From 4830e3766cc4892b6eefad567da2cc5fb3a4a677 Mon Sep 17 00:00:00 2001 From: loichyan Date: Tue, 28 Mar 2023 13:40:20 +0800 Subject: [PATCH] feat(cli): use `--verbose` to increase log level --- src/cli.rs | 2 ++ src/main.rs | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index a20d472..f427baf 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -13,6 +13,8 @@ pub struct Cli { /// Path(s) to load the icons cheat sheet or cached content. #[arg(short, long, value_name(V_PATH))] pub input: Vec, + #[arg(short, long, action = clap::ArgAction::Count)] + pub verbose: u8, #[command(subcommand)] pub cmd: Command, } diff --git a/src/main.rs b/src/main.rs index 5b398f0..6100892 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,18 +13,25 @@ use cli::Command; use prompt::YesOrNo; use runtime::{CheckerContext, Runtime}; use thisctx::WithContext; -use tracing::error; +use tracing::{error, Level}; static CACHED: &str = include_str!("./cached.txt"); fn main_impl() -> error::Result<()> { + let args = cli::Cli::parse(); + + let lv = match args.verbose { + 0 => Level::WARN, + 1 => Level::INFO, + 2 => Level::DEBUG, + _ => Level::TRACE, + }; let subscriber = tracing_subscriber::FmtSubscriber::builder() - .with_max_level(tracing::Level::WARN) + .with_max_level(lv) .without_time() .finish(); tracing::subscriber::set_global_default(subscriber).context(error::Any)?; - let args = cli::Cli::parse(); let mut rt = Runtime::builder(); if args.input.is_empty() { rt.load_cache(CACHED);