From ed08e7ad503082ca63385b18ff3f226339884ba7 Mon Sep 17 00:00:00 2001 From: R3ZV Date: Sun, 10 Nov 2024 16:35:44 +0200 Subject: [PATCH 1/3] Suppress recipe not found error code --- src/config.rs | 10 ++++++++++ src/run.rs | 7 +++++++ src/verbosity.rs | 5 +++++ tests/lib.rs | 1 + tests/recipe_exists.rs | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 tests/recipe_exists.rs diff --git a/src/config.rs b/src/config.rs index d0b91d67..8e519805 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 RECIPE_EXISTS: &str = "RECIPE-EXISTS"; 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::RECIPE_EXISTS) + .long("recipe-exists") + .env("JUST_RECIPE_EXISTS") + .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::RECIPE_EXISTS) { + Verbosity::RecipeQuiet } else { Verbosity::from_flag_occurrences(matches.get_count(arg::VERBOSE)) }, diff --git a/src/run.rs b/src/run.rs index a07b73bb..2f3d5a8c 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 f3ba3e45..20dc8a65 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/lib.rs b/tests/lib.rs index 7c85460b..9fdcd789 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -91,6 +91,7 @@ mod private; mod quiet; mod quote; mod readme; +mod recipe_exists; mod recursion_limit; mod regexes; mod run; diff --git a/tests/recipe_exists.rs b/tests/recipe_exists.rs new file mode 100644 index 00000000..dc727c6f --- /dev/null +++ b/tests/recipe_exists.rs @@ -0,0 +1,33 @@ +use super::*; + +#[test] +fn without_recipe_exists() { + 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(["--recipe-exists", "execute"]) + .justfile( + " + build: + echo \"Building...\" + ", + ) + .stderr("") + .stdout("") + .status(0) + .run(); +} From 9e9862fe6c046345dcecb8bfa07498276fa95548 Mon Sep 17 00:00:00 2001 From: R3ZV Date: Mon, 11 Nov 2024 08:38:52 +0200 Subject: [PATCH 2/3] Renamed recipe-exists to if-present --- src/config.rs | 10 +++++----- tests/{recipe_exists.rs => if_present.rs} | 4 ++-- tests/lib.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) rename tests/{recipe_exists.rs => if_present.rs} (86%) diff --git a/src/config.rs b/src/config.rs index 8e519805..23a04ed7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -103,7 +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 RECIPE_EXISTS: &str = "RECIPE-EXISTS"; + 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"; @@ -317,9 +317,9 @@ impl Config { .conflicts_with(arg::DRY_RUN), ) .arg( - Arg::new(arg::RECIPE_EXISTS) - .long("recipe-exists") - .env("JUST_RECIPE_EXISTS") + Arg::new(arg::IF_PRESENT) + .long("if-present") + .env("JUST_IF_PRESENT") .action(ArgAction::SetTrue) .help("Suppress error code"), ) @@ -759,7 +759,7 @@ impl Config { unstable, verbosity: if matches.get_flag(arg::QUIET) { Verbosity::Quiet - } else if matches.get_flag(arg::RECIPE_EXISTS) { + } else if matches.get_flag(arg::IF_PRESENT) { Verbosity::RecipeQuiet } else { Verbosity::from_flag_occurrences(matches.get_count(arg::VERBOSE)) diff --git a/tests/recipe_exists.rs b/tests/if_present.rs similarity index 86% rename from tests/recipe_exists.rs rename to tests/if_present.rs index dc727c6f..32054a29 100644 --- a/tests/recipe_exists.rs +++ b/tests/if_present.rs @@ -1,7 +1,7 @@ use super::*; #[test] -fn without_recipe_exists() { +fn without_if_present() { Test::new() .arg("execute") .justfile( @@ -19,7 +19,7 @@ fn without_recipe_exists() { #[test] fn ignore_unknown_recipe() { Test::new() - .args(["--recipe-exists", "execute"]) + .args(["--if-present", "execute"]) .justfile( " build: diff --git a/tests/lib.rs b/tests/lib.rs index 9fdcd789..2576e782 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; @@ -91,7 +92,6 @@ mod private; mod quiet; mod quote; mod readme; -mod recipe_exists; mod recursion_limit; mod regexes; mod run; From 4597aaddabc42796ef9adb7ea599006cbd3cf908 Mon Sep 17 00:00:00 2001 From: R3ZV Date: Sun, 17 Nov 2024 16:25:12 +0200 Subject: [PATCH 3/3] Config for allow missing --- src/config.rs | 12 ++++++------ src/run.rs | 13 ++++++------- src/verbosity.rs | 5 ----- tests/{if_present.rs => allow_missing.rs} | 4 ++-- tests/lib.rs | 2 +- 5 files changed, 15 insertions(+), 21 deletions(-) rename tests/{if_present.rs => allow_missing.rs} (86%) diff --git a/src/config.rs b/src/config.rs index 23a04ed7..11023fc8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,7 @@ pub(crate) struct Config { pub(crate) list_submodules: bool, pub(crate) load_dotenv: bool, pub(crate) no_aliases: bool, + pub(crate) allow_missing: bool, pub(crate) no_dependencies: bool, pub(crate) one: bool, pub(crate) search_config: SearchConfig, @@ -103,7 +104,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 ALLOW_MISSING: &str = "ALLOW-MISSING"; pub(crate) const SET: &str = "SET"; pub(crate) const SHELL: &str = "SHELL"; pub(crate) const SHELL_ARG: &str = "SHELL-ARG"; @@ -317,9 +318,9 @@ impl Config { .conflicts_with(arg::DRY_RUN), ) .arg( - Arg::new(arg::IF_PRESENT) - .long("if-present") - .env("JUST_IF_PRESENT") + Arg::new(arg::ALLOW_MISSING) + .long("allow-missing") + .env("JUST_ALLOW_MISSING") .action(ArgAction::SetTrue) .help("Suppress error code"), ) @@ -737,6 +738,7 @@ impl Config { list_submodules: matches.get_flag(arg::LIST_SUBMODULES), load_dotenv: !matches.get_flag(arg::NO_DOTENV), no_aliases: matches.get_flag(arg::NO_ALIASES), + allow_missing: matches.get_flag(arg::ALLOW_MISSING), no_dependencies: matches.get_flag(arg::NO_DEPS), one: matches.get_flag(arg::ONE), search_config, @@ -759,8 +761,6 @@ 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 2f3d5a8c..00b809d1 100644 --- a/src/run.rs +++ b/src/run.rs @@ -15,9 +15,9 @@ pub fn run(args: impl Iterator + Clone>) -> Result<() let config = Config::from_matches(&matches).map_err(Error::from); - let (color, verbosity) = config + let (color, verbosity, allow_missing) = config .as_ref() - .map(|config| (config.color, config.verbosity)) + .map(|config| (config.color, config.verbosity, config.allow_missing)) .unwrap_or_default(); let loader = Loader::new(); @@ -28,11 +28,10 @@ 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 allow_missing { + if let Error::UnknownRecipe { .. } = error { + return 0; + } } if !verbosity.quiet() && error.print_message() { diff --git a/src/verbosity.rs b/src/verbosity.rs index 20dc8a65..f3ba3e45 100644 --- a/src/verbosity.rs +++ b/src/verbosity.rs @@ -1,7 +1,6 @@ #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] pub(crate) enum Verbosity { Quiet, - RecipeQuiet, Taciturn, Loquacious, Grandiloquent, @@ -20,10 +19,6 @@ 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/allow_missing.rs similarity index 86% rename from tests/if_present.rs rename to tests/allow_missing.rs index 32054a29..2d74f27a 100644 --- a/tests/if_present.rs +++ b/tests/allow_missing.rs @@ -1,7 +1,7 @@ use super::*; #[test] -fn without_if_present() { +fn fail_on_unknown_recipe() { Test::new() .arg("execute") .justfile( @@ -19,7 +19,7 @@ fn without_if_present() { #[test] fn ignore_unknown_recipe() { Test::new() - .args(["--if-present", "execute"]) + .args(["--allow-missing", "execute"]) .justfile( " build: diff --git a/tests/lib.rs b/tests/lib.rs index 2576e782..fb0cf661 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -33,6 +33,7 @@ mod test; mod allow_duplicate_recipes; mod allow_duplicate_variables; +mod allow_missing; mod assert_stdout; mod assert_success; mod assertions; @@ -64,7 +65,6 @@ mod functions; #[cfg(unix)] mod global; mod groups; -mod if_present; mod ignore_comments; mod imports; mod init;