From 8c66eff40a014ef73f30818fa1ed0335c60c7983 Mon Sep 17 00:00:00 2001 From: JustAnotherID Date: Sat, 12 Oct 2024 15:31:24 +0800 Subject: [PATCH] Add `--strict` argument for cli --- autocorrect-cli/src/cli.rs | 7 +++++++ autocorrect-cli/src/lib.rs | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/autocorrect-cli/src/cli.rs b/autocorrect-cli/src/cli.rs index d308fc3..cfdf7b9 100644 --- a/autocorrect-cli/src/cli.rs +++ b/autocorrect-cli/src/cli.rs @@ -78,6 +78,13 @@ pub(crate) struct Cli { help = "Disable diff background color for diff output." )] pub no_diff_bg_color: bool, + + #[clap( + long, + help = "Strict mode will cause warnings to return a non-zero value.", + default_value = "false" + )] + pub strict: bool, } #[derive(Debug, Subcommand, Clone)] diff --git a/autocorrect-cli/src/lib.rs b/autocorrect-cli/src/lib.rs index f70dcbe..16e427b 100644 --- a/autocorrect-cli/src/lib.rs +++ b/autocorrect-cli/src/lib.rs @@ -262,6 +262,10 @@ where // Exit with code = 1 std::process::exit(1); } + if cli.strict && _warn_count > 0 { + // Exit with code = 1 + std::process::exit(1); + } } else if cli.formatter == cli::OutputFormatter::Json { log::info!("{}", autocorrect::json::to_lint_results_json(lint_results)); } else {