From 8b1c4fce6bc5235b3e27106bb32b87ad7378148c Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 27 Aug 2022 18:11:49 -0400 Subject: [PATCH] Add exit-zero --- src/bin/rust_python_linter.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/bin/rust_python_linter.rs b/src/bin/rust_python_linter.rs index 8667486af8..95e90370f6 100644 --- a/src/bin/rust_python_linter.rs +++ b/src/bin/rust_python_linter.rs @@ -1,9 +1,10 @@ use std::path::{Path, PathBuf}; +use std::process::ExitCode; use std::sync::mpsc::channel; use std::time::Instant; use anyhow::Result; -use clap::{Parser, ValueHint}; +use clap::Parser; use colored::Colorize; use log::{debug, error}; use notify::{raw_watcher, RecursiveMode, Watcher}; @@ -28,6 +29,8 @@ struct Cli { #[clap(short, long, action)] quiet: bool, #[clap(short, long, action)] + exit_zero: bool, + #[clap(short, long, action)] watch: bool, #[clap(short, long, action)] no_cache: bool, @@ -92,7 +95,7 @@ fn report_continuously(messages: &[Message]) -> Result<()> { Ok(()) } -fn main() -> Result<()> { +fn inner_main() -> Result { let cli = Cli::parse(); set_up_logging(cli.verbose)?; @@ -141,7 +144,18 @@ fn main() -> Result<()> { if !cli.quiet { report_once(&messages)?; } + + if !messages.is_empty() && !cli.exit_zero { + return Ok(ExitCode::FAILURE); + } } - Ok(()) + Ok(ExitCode::SUCCESS) +} + +fn main() -> ExitCode { + match inner_main() { + Ok(code) => code, + Err(_) => ExitCode::FAILURE, + } }