diff --git a/cli/flags.rs b/cli/flags.rs index b0e4b32edd..e1b2948387 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -512,14 +512,10 @@ To evaluate code in the shell: "; /// Main entry point for parsing deno's command line flags. -pub fn flags_from_vec(args: I) -> clap::Result -where - I: IntoIterator, - T: Into + Clone, -{ +pub fn flags_from_vec(args: Vec) -> clap::Result { let version = crate::version::deno(); let app = clap_root(&version); - let matches = app.clone().try_get_matches_from(args)?; + let matches = app.clone().try_get_matches_from(&args)?; let mut flags = Flags::default(); @@ -554,7 +550,7 @@ where Some(("lsp", m)) => lsp_parse(&mut flags, m), Some(("repl", m)) => repl_parse(&mut flags, m), Some(("run", m)) => run_parse(&mut flags, m), - Some(("task", m)) => task_parse(&mut flags, m), + Some(("task", m)) => task_parse(&mut flags, m, &args), Some(("test", m)) => test_parse(&mut flags, m), Some(("types", m)) => types_parse(&mut flags, m), Some(("uninstall", m)) => uninstall_parse(&mut flags, m), @@ -2500,20 +2496,25 @@ fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) { flags.subcommand = DenoSubcommand::Run(RunFlags { script }); } -fn task_parse(flags: &mut Flags, matches: &clap::ArgMatches) { +fn task_parse( + flags: &mut Flags, + matches: &clap::ArgMatches, + raw_args: &[String], +) { config_arg_parse(flags, matches); let mut task_name = "".to_string(); if let Some(task) = matches.value_of("task") { task_name = task.to_string(); - let task_args: Vec = matches - .values_of("task_args") - .unwrap_or_default() - .map(String::from) - .collect(); - for v in task_args { - flags.argv.push(v); + if let Some(task_args) = matches.values_of("task_args") { + // forward the `--` to the deno task + if let Some(index) = matches.index_of("task_args") { + if raw_args[index] == "--" { + flags.argv.push("--".to_string()); + } + } + flags.argv.extend(task_args.map(String::from)); } } @@ -2961,6 +2962,7 @@ pub fn resolve_urls(urls: Vec) -> Vec { #[cfg(test)] mod tests { use super::*; + use pretty_assertions::assert_eq; /// Creates vector of strings, Vec macro_rules! svec { @@ -5492,8 +5494,7 @@ mod tests { #[test] fn task_subcommand() { - let r = - flags_from_vec(svec!["deno", "task", "build", "--", "hello", "world",]); + let r = flags_from_vec(svec!["deno", "task", "build", "hello", "world",]); assert_eq!( r.unwrap(), Flags { @@ -5517,9 +5518,34 @@ mod tests { ); } + #[test] + fn task_subcommand_double_hyphen() { + let r = flags_from_vec(svec![ + "deno", + "task", + "-c", + "deno.json", + "build", + "--", + "hello", + "world", + ]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Task(TaskFlags { + task: "build".to_string(), + }), + argv: svec!["--", "hello", "world"], + config_path: Some("deno.json".to_string()), + ..Flags::default() + } + ); + } + #[test] fn task_subcommand_empty() { - let r = flags_from_vec(svec!["deno", "task",]); + let r = flags_from_vec(svec!["deno", "task"]); assert_eq!( r.unwrap(), Flags { diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs index 92964de875..77a3266186 100644 --- a/cli/lsp/testing/execution.rs +++ b/cli/lsp/testing/execution.rs @@ -300,7 +300,8 @@ impl TestRun { ) -> Result<(), AnyError> { let args = self.get_args(); lsp_log!("Executing test run with arguments: {}", args.join(" ")); - let flags = flags::flags_from_vec(args)?; + let flags = + flags::flags_from_vec(args.into_iter().map(String::from).collect())?; let ps = proc_state::ProcState::build(Arc::new(flags)).await?; let permissions = Permissions::from_options(&ps.flags.permissions_options());