diff --git a/src/app.rs b/src/app.rs index 87630ccd..e4a32a0e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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::>()) + .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::>(); + + let arguments = if !rest.is_empty() { rest } else if let Some(recipe) = justfile.first() { vec![recipe] diff --git a/src/integration.rs b/src/integration.rs index 5b735784..71a788f1 100644 --- a/src/integration.rs +++ b/src/integration.rs @@ -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(