From e7df35a765185a61a57c04c0cd71dbe59c4e860b Mon Sep 17 00:00:00 2001 From: Bauke Date: Thu, 18 Jan 2024 14:37:02 +0100 Subject: [PATCH] Add the --noise-level option and implementation. --- hooked-cli/source/cli/mod.rs | 9 ++++++++- hooked-cli/source/cli/run.rs | 18 ++++++++++++------ hooked-cli/source/main.rs | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/hooked-cli/source/cli/mod.rs b/hooked-cli/source/cli/mod.rs index 6467640..f23965a 100644 --- a/hooked-cli/source/cli/mod.rs +++ b/hooked-cli/source/cli/mod.rs @@ -2,7 +2,10 @@ use std::path::PathBuf; -use clap::{Args as Arguments, Parser, Subcommand}; +use { + clap::{Args as Arguments, Parser, Subcommand}, + hooked_config::NoiseLevel, +}; #[cfg(debug_assertions)] mod cli_reference; @@ -69,6 +72,10 @@ pub struct RunArgs { /// The hook type to run. #[clap(value_parser = crate::HOOK_TYPES)] pub hook_type: String, + + /// The noise level to override for all hooks. + #[clap(long)] + pub noise_level: Option, } /// The `cli-reference` subcommand arguments. diff --git a/hooked-cli/source/cli/run.rs b/hooked-cli/source/cli/run.rs index 9aa56b9..0a5142c 100644 --- a/hooked-cli/source/cli/run.rs +++ b/hooked-cli/source/cli/run.rs @@ -10,15 +10,17 @@ use { }; use crate::{ + cli::RunArgs, printer::{print, PrintType, PRINT_STYLE}, utilities::{globset_from_strings, plural}, }; /// The `run` subcommand. -pub fn hooked_run(config: Config, hook_type: String) -> Result<()> { +pub fn hooked_run(config: Config, args: RunArgs) -> Result<()> { + let cli_noise_level = args.noise_level.as_ref(); let global_noise_level = &config.general.noise_level; - if hook_type == "pre-commit" { + if args.hook_type == "pre-commit" { let hook_count = config.pre_commit.len(); print( format!( @@ -26,7 +28,7 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> { hook_count, plural(hook_count, "hook", None) ), - &config.general.noise_level, + cli_noise_level.unwrap_or(global_noise_level), PrintType::Info, ); @@ -47,7 +49,7 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> { "≫".style(PRINT_STYLE.skipped), hook_name.style(PRINT_STYLE.skipped) ), - global_noise_level, + cli_noise_level.unwrap_or(global_noise_level), PrintType::Info, ); continue 'hook_loop; @@ -100,11 +102,15 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> { hook.noise_level.as_ref().unwrap_or(global_noise_level); print( format!("\t{} {}", prefix.style(style), hook_name.style(style)), - hook_noise_level, + cli_noise_level.unwrap_or(hook_noise_level), print_type, ); if !output.is_empty() && print_output { - print(output, hook_noise_level, PrintType::Info); + print( + output, + cli_noise_level.unwrap_or(hook_noise_level), + PrintType::Info, + ); } if stop { diff --git a/hooked-cli/source/main.rs b/hooked-cli/source/main.rs index 41fea22..43c11b3 100644 --- a/hooked-cli/source/main.rs +++ b/hooked-cli/source/main.rs @@ -36,7 +36,7 @@ fn main() -> Result<()> { } MainSubcommands::Run(sub_args) => { - cli::hooked_run(config, sub_args.hook_type)?; + cli::hooked_run(config, sub_args)?; } #[cfg(debug_assertions)]