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:
Casey Rodarmor 2016-11-13 21:26:28 -08:00 committed by GitHub
parent aaee7341c4
commit 91d1e59667
2 changed files with 31 additions and 12 deletions

View File

@ -265,18 +265,18 @@ pub fn app() {
let override_re = regex::Regex::new("^([^=]+)=(.*)$").unwrap();
let arguments = if let Some(arguments) = matches.values_of("arguments") {
let mut done = false;
let mut rest = vec![];
for argument in arguments {
if !done && override_re.is_match(argument) {
let captures = override_re.captures(argument).unwrap();
overrides.insert(captures.at(1).unwrap(), captures.at(2).unwrap());
} else {
rest.push(argument);
done = true;
}
}
let raw_arguments = matches.values_of("arguments").map(|values| values.collect::<Vec<_>>())
.unwrap_or_default();
for argument in raw_arguments.iter().take_while(|arg| override_re.is_match(arg)) {
let captures = override_re.captures(argument).unwrap();
overrides.insert(captures.at(1).unwrap(), captures.at(2).unwrap());
}
let rest = raw_arguments.iter().skip_while(|arg| override_re.is_match(arg))
.cloned().collect::<Vec<_>>();
let arguments = if !rest.is_empty() {
rest
} else if let Some(recipe) = justfile.first() {
vec![recipe]

View File

@ -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]
fn export_shebang() {
integration_test(