Add the --noise-level option and implementation.

This commit is contained in:
Bauke 2024-01-18 14:37:02 +01:00
parent a9ee3c20fe
commit e7df35a765
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 21 additions and 8 deletions

View File

@ -2,7 +2,10 @@
use std::path::PathBuf; use std::path::PathBuf;
use clap::{Args as Arguments, Parser, Subcommand}; use {
clap::{Args as Arguments, Parser, Subcommand},
hooked_config::NoiseLevel,
};
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
mod cli_reference; mod cli_reference;
@ -69,6 +72,10 @@ pub struct RunArgs {
/// The hook type to run. /// The hook type to run.
#[clap(value_parser = crate::HOOK_TYPES)] #[clap(value_parser = crate::HOOK_TYPES)]
pub hook_type: String, pub hook_type: String,
/// The noise level to override for all hooks.
#[clap(long)]
pub noise_level: Option<NoiseLevel>,
} }
/// The `cli-reference` subcommand arguments. /// The `cli-reference` subcommand arguments.

View File

@ -10,15 +10,17 @@ use {
}; };
use crate::{ use crate::{
cli::RunArgs,
printer::{print, PrintType, PRINT_STYLE}, printer::{print, PrintType, PRINT_STYLE},
utilities::{globset_from_strings, plural}, utilities::{globset_from_strings, plural},
}; };
/// The `run` subcommand. /// 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; 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(); let hook_count = config.pre_commit.len();
print( print(
format!( format!(
@ -26,7 +28,7 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
hook_count, hook_count,
plural(hook_count, "hook", None) plural(hook_count, "hook", None)
), ),
&config.general.noise_level, cli_noise_level.unwrap_or(global_noise_level),
PrintType::Info, PrintType::Info,
); );
@ -47,7 +49,7 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
"".style(PRINT_STYLE.skipped), "".style(PRINT_STYLE.skipped),
hook_name.style(PRINT_STYLE.skipped) hook_name.style(PRINT_STYLE.skipped)
), ),
global_noise_level, cli_noise_level.unwrap_or(global_noise_level),
PrintType::Info, PrintType::Info,
); );
continue 'hook_loop; 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); hook.noise_level.as_ref().unwrap_or(global_noise_level);
print( print(
format!("\t{} {}", prefix.style(style), hook_name.style(style)), format!("\t{} {}", prefix.style(style), hook_name.style(style)),
hook_noise_level, cli_noise_level.unwrap_or(hook_noise_level),
print_type, print_type,
); );
if !output.is_empty() && print_output { 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 { if stop {

View File

@ -36,7 +36,7 @@ fn main() -> Result<()> {
} }
MainSubcommands::Run(sub_args) => { MainSubcommands::Run(sub_args) => {
cli::hooked_run(config, sub_args.hook_type)?; cli::hooked_run(config, sub_args)?;
} }
#[cfg(debug_assertions)] #[cfg(debug_assertions)]