Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress recipe not found error code #2460

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
},
Expand Down
7 changes: 7 additions & 0 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ pub fn run(args: impl Iterator<Item = impl Into<OsString> + 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()));
}
Expand Down
5 changes: 5 additions & 0 deletions src/verbosity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub(crate) enum Verbosity {
Quiet,
RecipeQuiet,
Taciturn,
Loquacious,
Grandiloquent,
Expand All @@ -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()
}
Expand Down
33 changes: 33 additions & 0 deletions tests/if_present.rs
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mod functions;
#[cfg(unix)]
mod global;
mod groups;
mod if_present;
mod ignore_comments;
mod imports;
mod init;
Expand Down