Fix override argument processing bug (#115)
An invocation like `just foo=bar` would lead to no recipe being run due to the way that override arguments were being processed. Fix that and add a test that covers that case.
This commit is contained in:
parent
aaee7341c4
commit
91d1e59667
24
src/app.rs
24
src/app.rs
@ -265,18 +265,18 @@ pub fn app() {
|
|||||||
|
|
||||||
let override_re = regex::Regex::new("^([^=]+)=(.*)$").unwrap();
|
let override_re = regex::Regex::new("^([^=]+)=(.*)$").unwrap();
|
||||||
|
|
||||||
let arguments = if let Some(arguments) = matches.values_of("arguments") {
|
let raw_arguments = matches.values_of("arguments").map(|values| values.collect::<Vec<_>>())
|
||||||
let mut done = false;
|
.unwrap_or_default();
|
||||||
let mut rest = vec![];
|
|
||||||
for argument in arguments {
|
for argument in raw_arguments.iter().take_while(|arg| override_re.is_match(arg)) {
|
||||||
if !done && override_re.is_match(argument) {
|
let captures = override_re.captures(argument).unwrap();
|
||||||
let captures = override_re.captures(argument).unwrap();
|
overrides.insert(captures.at(1).unwrap(), captures.at(2).unwrap());
|
||||||
overrides.insert(captures.at(1).unwrap(), captures.at(2).unwrap());
|
}
|
||||||
} else {
|
|
||||||
rest.push(argument);
|
let rest = raw_arguments.iter().skip_while(|arg| override_re.is_match(arg))
|
||||||
done = true;
|
.cloned().collect::<Vec<_>>();
|
||||||
}
|
|
||||||
}
|
let arguments = if !rest.is_empty() {
|
||||||
rest
|
rest
|
||||||
} else if let Some(recipe) = justfile.first() {
|
} else if let Some(recipe) = justfile.first() {
|
||||||
vec![recipe]
|
vec![recipe]
|
||||||
|
@ -660,6 +660,25 @@ wut:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn export_override() {
|
||||||
|
integration_test(
|
||||||
|
&["foo=hello", "--set", "bar", "bye"],
|
||||||
|
r#"
|
||||||
|
export foo = "a"
|
||||||
|
baz = "c"
|
||||||
|
export bar = "b"
|
||||||
|
export abc = foo + "-" + bar + "-" + baz
|
||||||
|
|
||||||
|
wut:
|
||||||
|
echo $foo $bar $abc
|
||||||
|
"#,
|
||||||
|
0,
|
||||||
|
"hello bye hello-bye-c\n",
|
||||||
|
"echo $foo $bar $abc\n",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn export_shebang() {
|
fn export_shebang() {
|
||||||
integration_test(
|
integration_test(
|
||||||
|
Loading…
Reference in New Issue
Block a user