Allow evaluating justfiles with no recipes (#794)

This commit is contained in:
Casey Rodarmor 2021-04-05 21:17:53 -07:00 committed by GitHub
parent dd578d141c
commit da97f8d7dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 36 deletions

View File

@ -61,23 +61,6 @@ impl<'src> Justfile<'src> {
overrides: &'run BTreeMap<String, String>, overrides: &'run BTreeMap<String, String>,
arguments: &'run [String], arguments: &'run [String],
) -> RunResult<'run, ()> { ) -> RunResult<'run, ()> {
let argvec: Vec<&str> = if !arguments.is_empty() {
arguments.iter().map(String::as_str).collect()
} else if let Some(recipe) = self.first() {
let min_arguments = recipe.min_arguments();
if min_arguments > 0 {
return Err(RuntimeError::DefaultRecipeRequiresArguments {
recipe: recipe.name.lexeme(),
min_arguments,
});
}
vec![recipe.name()]
} else {
return Err(RuntimeError::NoRecipes);
};
let arguments = argvec.as_slice();
let unknown_overrides = overrides let unknown_overrides = overrides
.keys() .keys()
.filter(|name| !self.assignments.contains_key(name.as_str())) .filter(|name| !self.assignments.contains_key(name.as_str()))
@ -142,6 +125,23 @@ impl<'src> Justfile<'src> {
return Ok(()); return Ok(());
} }
let argvec: Vec<&str> = if !arguments.is_empty() {
arguments.iter().map(String::as_str).collect()
} else if let Some(recipe) = self.first() {
let min_arguments = recipe.min_arguments();
if min_arguments > 0 {
return Err(RuntimeError::DefaultRecipeRequiresArguments {
recipe: recipe.name.lexeme(),
min_arguments,
});
}
vec![recipe.name()]
} else {
return Err(RuntimeError::NoRecipes);
};
let arguments = argvec.as_slice();
let mut missing = vec![]; let mut missing = vec![];
let mut grouped = vec![]; let mut grouped = vec![];
let mut rest = arguments; let mut rest = arguments;

29
tests/evaluate.rs Normal file
View File

@ -0,0 +1,29 @@
test! {
name: evaluate,
justfile: r#"
foo := "a\t"
hello := "c"
bar := "b\t"
ab := foo + bar + hello
wut:
touch /this/is/not/a/file
"#,
args: ("--evaluate"),
stdout: r#"ab := "a b c"
bar := "b "
foo := "a "
hello := "c"
"#,
}
test! {
name: evaluate_empty,
justfile: "
a := 'foo'
",
args: ("--evaluate"),
stdout: r#"
a := "foo"
"#,
}

View File

@ -10,6 +10,7 @@ mod delimiters;
mod dotenv; mod dotenv;
mod edit; mod edit;
mod error_messages; mod error_messages;
mod evaluate;
mod examples; mod examples;
mod export; mod export;
mod init; mod init;

View File

@ -569,25 +569,6 @@ echo `echo command interpolation`
", ",
} }
test! {
name: evaluate,
justfile: r#"
foo := "a\t"
hello := "c"
bar := "b\t"
ab := foo + bar + hello
wut:
touch /this/is/not/a/file
"#,
args: ("--evaluate"),
stdout: r#"ab := "a b c"
bar := "b "
foo := "a "
hello := "c"
"#,
}
test! { test! {
name: line_error_spacing, name: line_error_spacing,
justfile: r#" justfile: r#"