diff --git a/src/cli/run.rs b/src/cli/run.rs index 8c36126a30..994f661ba0 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -464,6 +464,8 @@ impl Run { for (script, args) in task.render_run_scripts_with_args(self.cd.clone(), &task.args, &env)? { + let get_args = || task.run.iter().chain(task.args.iter()).cloned().collect(); + self.parse_usage_spec_and_init_env(task, &mut env, get_args)?; self.exec_script(&script, &args, task, &env, &prefix)?; } } @@ -578,14 +580,8 @@ impl Run { let mut env = env.clone(); let command = file.to_string_lossy().to_string(); let args = task.args.iter().cloned().collect_vec(); - let (spec, _) = task.parse_usage_spec(self.cd.clone(), &env)?; - if !spec.cmd.args.is_empty() || !spec.cmd.flags.is_empty() { - let args = once(command.clone()).chain(args.clone()).collect_vec(); - let po = usage::parse(&spec, &args).map_err(|err| eyre!(err))?; - for (k, v) in po.as_env() { - env.insert(k, v); - } - } + let get_args = || once(command.clone()).chain(args.clone()).collect_vec(); + self.parse_usage_spec_and_init_env(task, &mut env, get_args)?; if !self.quiet(Some(task)) { let cmd = format!("{} {}", display_path(file), args.join(" ")) @@ -599,6 +595,24 @@ impl Run { self.exec(file, &args, task, &env, prefix) } + fn parse_usage_spec_and_init_env( + &self, + task: &Task, + env: &mut EnvMap, + get_args: impl Fn() -> Vec, + ) -> Result<()> { + let (spec, _) = task.parse_usage_spec(self.cd.clone(), env)?; + if !spec.cmd.args.is_empty() || !spec.cmd.flags.is_empty() { + let args: Vec = get_args(); + let po = usage::parse(&spec, &args).map_err(|err| eyre!(err))?; + for (k, v) in po.as_env() { + env.insert(k, v); + } + } + + Ok(()) + } + fn exec( &self, file: &Path,