From 91d1e59667abdde4b4f60d049d6489083c602f1b Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 13 Nov 2016 21:26:28 -0800 Subject: [PATCH] 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. --- src/app.rs | 24 ++++++++++++------------ src/integration.rs | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/app.rs b/src/app.rs index 87630cc..e4a32a0 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 5b73578..71a788f 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(