diff --git a/src/check.rs b/src/check.rs index af9f879..904a780 100644 --- a/src/check.rs +++ b/src/check.rs @@ -128,7 +128,7 @@ where let mut command = Command::new("nix"); command.args(args_vec); - log::debug!("run command: {:?}", command_vec); + log::trace!("run command: {:?}", command_vec); let output = get_command_output(command)?; @@ -138,7 +138,7 @@ where stdout: String::from_utf8(output.stdout)?, stderr: String::from_utf8(output.stderr)?, }; - log::debug!("command called:\n{}", process_info); + log::trace!("command called:\n{}", process_info); if !output.status.success() { return Err(Error::ProcessFailed(process_info)); } diff --git a/src/main.rs b/src/main.rs index 44e2e8e..60df8f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,9 +9,8 @@ use error::Error; use options::{Commands, Options}; fn main() { - init_logger(); - let options = options::Options::parse(); + init_logger(&options); log::debug!("options = {:#?}", options); if let Err(e) = main_result(options) { log::error!("{}", e); @@ -27,11 +26,16 @@ fn main_result(options: Options) -> Result<(), Error> { Ok(()) } -fn init_logger() { +fn init_logger(options: &Options) { let mut builder = pretty_env_logger::formatted_builder(); + let default_level = match options.verbose { + 0 => "info", + 1 => "debug", + _ => "trace", + }; let filters = match std::env::var("RUST_LOG") { Ok(f) => f, - Err(_) => "flat_flake=info".to_string(), + Err(_) => format!("flat_flake={default_level}"), }; builder.parse_filters(&filters); builder.init() diff --git a/src/options.rs b/src/options.rs index 7037b02..f3a3b26 100644 --- a/src/options.rs +++ b/src/options.rs @@ -7,6 +7,9 @@ use clap::{Parser, Subcommand}; pub struct Options { #[command(subcommand)] pub command: Commands, + #[arg(short, long, global = true, action = clap::ArgAction::Count, + help = "Increase logging verbosity, override by RUST_LOG")] + pub verbose: u8, } #[derive(Clone, Debug, Subcommand)]