Skip to content

Commit

Permalink
Config for allow missing
Browse files Browse the repository at this point in the history
  • Loading branch information
R3ZV committed Nov 17, 2024
1 parent 9e9862f commit 4597aad
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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"),
)
Expand Down Expand Up @@ -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,
Expand All @@ -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))
},
Expand Down
13 changes: 6 additions & 7 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub fn run(args: impl Iterator<Item = impl Into<OsString> + 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();
Expand All @@ -28,11 +28,10 @@ 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 allow_missing {
if let Error::UnknownRecipe { .. } = error {
return 0;
}
}

if !verbosity.quiet() && error.print_message() {
Expand Down
5 changes: 0 additions & 5 deletions src/verbosity.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub(crate) enum Verbosity {
Quiet,
RecipeQuiet,
Taciturn,
Loquacious,
Grandiloquent,
Expand All @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions tests/if_present.rs → tests/allow_missing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

#[test]
fn without_if_present() {
fn fail_on_unknown_recipe() {
Test::new()
.arg("execute")
.justfile(
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,7 +65,6 @@ mod functions;
#[cfg(unix)]
mod global;
mod groups;
mod if_present;
mod ignore_comments;
mod imports;
mod init;
Expand Down

0 comments on commit 4597aad

Please sign in to comment.