Add exit-zero

This commit is contained in:
Charlie Marsh 2022-08-27 18:11:49 -04:00
parent 1fb3db92f1
commit 8b1c4fce6b
1 changed files with 17 additions and 3 deletions

View File

@ -1,9 +1,10 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::ExitCode;
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::time::Instant; use std::time::Instant;
use anyhow::Result; use anyhow::Result;
use clap::{Parser, ValueHint}; use clap::Parser;
use colored::Colorize; use colored::Colorize;
use log::{debug, error}; use log::{debug, error};
use notify::{raw_watcher, RecursiveMode, Watcher}; use notify::{raw_watcher, RecursiveMode, Watcher};
@ -28,6 +29,8 @@ struct Cli {
#[clap(short, long, action)] #[clap(short, long, action)]
quiet: bool, quiet: bool,
#[clap(short, long, action)] #[clap(short, long, action)]
exit_zero: bool,
#[clap(short, long, action)]
watch: bool, watch: bool,
#[clap(short, long, action)] #[clap(short, long, action)]
no_cache: bool, no_cache: bool,
@ -92,7 +95,7 @@ fn report_continuously(messages: &[Message]) -> Result<()> {
Ok(()) Ok(())
} }
fn main() -> Result<()> { fn inner_main() -> Result<ExitCode> {
let cli = Cli::parse(); let cli = Cli::parse();
set_up_logging(cli.verbose)?; set_up_logging(cli.verbose)?;
@ -141,7 +144,18 @@ fn main() -> Result<()> {
if !cli.quiet { if !cli.quiet {
report_once(&messages)?; 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,
}
} }