Skip duplicate recipe arguments (#1174)

This commit is contained in:
Casey Rodarmor 2022-05-03 22:04:55 -07:00 committed by GitHub
parent 8baebadd18
commit db35a58a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 18 deletions

View File

@ -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,
@ -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()];
let arguments = arguments
.iter()
.map(|argument| evaluator.evaluate_expression(argument))
.collect::<RunResult<Vec<String>>>()?;
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)?;
}
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)?;
@ -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(())
}

View File

@ -33,6 +33,7 @@ mod quiet;
mod quote;
mod readme;
mod regexes;
mod run;
mod search;
mod shebang;
mod shell;

19
tests/run.rs Normal file
View File

@ -0,0 +1,19 @@
use crate::common::*;
#[test]
fn dont_run_duplicate_recipes() {
Test::new()
.justfile(
"
foo:
# foo
",
)
.args(&["foo", "foo"])
.stderr(
"
# foo
",
)
.run();
}