diff --git a/src/config.rs b/src/config.rs index d0b91d671b..23a04ed79a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -103,6 +103,7 @@ mod arg { pub(crate) const NO_HIGHLIGHT: &str = "NO-HIGHLIGHT"; pub(crate) const ONE: &str = "ONE"; pub(crate) const QUIET: &str = "QUIET"; + pub(crate) const IF_PRESENT: &str = "IF-PRESENT"; pub(crate) const SET: &str = "SET"; pub(crate) const SHELL: &str = "SHELL"; pub(crate) const SHELL_ARG: &str = "SHELL-ARG"; @@ -315,6 +316,13 @@ impl Config { .help("Suppress all output") .conflicts_with(arg::DRY_RUN), ) + .arg( + Arg::new(arg::IF_PRESENT) + .long("if-present") + .env("JUST_IF_PRESENT") + .action(ArgAction::SetTrue) + .help("Suppress error code"), + ) .arg( Arg::new(arg::SET) .long("set") @@ -751,6 +759,8 @@ impl Config { unstable, verbosity: if matches.get_flag(arg::QUIET) { Verbosity::Quiet + } else if matches.get_flag(arg::IF_PRESENT) { + Verbosity::RecipeQuiet } else { Verbosity::from_flag_occurrences(matches.get_count(arg::VERBOSE)) }, diff --git a/src/run.rs b/src/run.rs index a07b73bbc9..2f3d5a8c8b 100644 --- a/src/run.rs +++ b/src/run.rs @@ -28,6 +28,13 @@ pub fn run(args: impl Iterator + Clone>) -> Result<() config.subcommand.execute(&config, &loader) }) .map_err(|error| { + if verbosity.recipe_quiet() { + match error { + Error::UnknownRecipe { .. } => return 0, + _ => {} + }; + } + if !verbosity.quiet() && error.print_message() { eprintln!("{}", error.color_display(color.stderr())); } diff --git a/src/verbosity.rs b/src/verbosity.rs index f3ba3e4585..20dc8a65eb 100644 --- a/src/verbosity.rs +++ b/src/verbosity.rs @@ -1,6 +1,7 @@ #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] pub(crate) enum Verbosity { Quiet, + RecipeQuiet, Taciturn, Loquacious, Grandiloquent, @@ -19,6 +20,10 @@ impl Verbosity { self == Self::Quiet } + pub(crate) fn recipe_quiet(self) -> bool { + self == Self::RecipeQuiet + } + pub(crate) fn loud(self) -> bool { !self.quiet() } diff --git a/tests/if_present.rs b/tests/if_present.rs new file mode 100644 index 0000000000..32054a29da --- /dev/null +++ b/tests/if_present.rs @@ -0,0 +1,33 @@ +use super::*; + +#[test] +fn without_if_present() { + Test::new() + .arg("execute") + .justfile( + " + build: + echo \"Building...\" + ", + ) + .stderr("error: Justfile does not contain recipe `execute`.\n") + .stdout("") + .status(1) + .run(); +} + +#[test] +fn ignore_unknown_recipe() { + Test::new() + .args(["--if-present", "execute"]) + .justfile( + " + build: + echo \"Building...\" + ", + ) + .stderr("") + .stdout("") + .status(0) + .run(); +} diff --git a/tests/lib.rs b/tests/lib.rs index 7c85460b44..2576e78289 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -64,6 +64,7 @@ mod functions; #[cfg(unix)] mod global; mod groups; +mod if_present; mod ignore_comments; mod imports; mod init;