Skip to content

Commit

Permalink
Skip duplicate recipe arguments (#1174)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored May 4, 2022
1 parent 8baebad commit db35a58
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,15 @@ impl<'src> Justfile<'src> {
search: &Search,
ran: &mut BTreeSet<Vec<String>>,
) -> RunResult<'src, ()> {
let mut invocation = vec![recipe.name().to_owned()];
for argument in arguments {
invocation.push((*argument).to_string());
}

if ran.contains(&invocation) {
return Ok(());
}

let (outer, positional) = Evaluator::evaluate_parameters(
context.config,
dotenv,
Expand All @@ -300,20 +309,19 @@ impl<'src> Justfile<'src> {
Evaluator::recipe_evaluator(context.config, dotenv, &scope, context.settings, search);

for Dependency { recipe, arguments } in recipe.dependencies.iter().take(recipe.priors) {
let mut invocation = vec![recipe.name().to_owned()];

for argument in arguments {
invocation.push(evaluator.evaluate_expression(argument)?);
}

if !ran.contains(&invocation) {
let arguments = invocation
.iter()
.skip(1)
.map(String::as_ref)
.collect::<Vec<&str>>();
self.run_recipe(context, recipe, &arguments, dotenv, search, ran)?;
}
let arguments = arguments
.iter()
.map(|argument| evaluator.evaluate_expression(argument))
.collect::<RunResult<Vec<String>>>()?;

self.run_recipe(
context,
recipe,
&arguments.iter().map(String::as_ref).collect::<Vec<&str>>(),
dotenv,
search,
ran,
)?;
}

recipe.run(context, dotenv, scope.child(), search, &positional)?;
Expand All @@ -339,11 +347,6 @@ impl<'src> Justfile<'src> {
}
}

let mut invocation = vec![recipe.name().to_owned()];
for argument in arguments {
invocation.push((*argument).to_string());
}

ran.insert(invocation);
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod quiet;
mod quote;
mod readme;
mod regexes;
mod run;
mod search;
mod shebang;
mod shell;
Expand Down
19 changes: 19 additions & 0 deletions tests/run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::common::*;

#[test]
fn dont_run_duplicate_recipes() {
Test::new()
.justfile(
"
foo:
# foo
",
)
.args(&["foo", "foo"])
.stderr(
"
# foo
",
)
.run();
}

0 comments on commit db35a58

Please sign in to comment.