diff options
author | Cre3per <12541974+Cre3per@users.noreply.github.com> | 2022-08-10 17:55:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-10 11:55:34 -0400 |
commit | afc29c28aedcba016a5c4205080c5907fd7bde0b (patch) | |
tree | b7cd22476527544cd8ba228dbe343d13a4a0688a | |
parent | bdd8ddbe4cc4d23b7c1827f37ff7a0cc61980fa4 (diff) |
fix(task): subcommand parser skips global args (#15297)
-rw-r--r-- | cli/args/flags.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index f4a379cf7..9feef54b0 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -2582,7 +2582,8 @@ fn task_parse( } if let Some(mut index) = matches.index_of("task_name_and_args") { - index += 1; // skip `task` + let task_word_index = raw_args.iter().position(|el| el == "task").unwrap(); + let raw_args = &raw_args[task_word_index..]; // temporary workaround until https://github.com/clap-rs/clap/issues/1538 is fixed while index < raw_args.len() { @@ -5765,6 +5766,25 @@ mod tests { } #[test] + fn task_with_global_flags() { + // can fail if the custom parser in task_parse() starts at the wrong index + let r = + flags_from_vec(svec!["deno", "--quiet", "--unstable", "task", "build"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Task(TaskFlags { + cwd: None, + task: "build".to_string(), + }), + unstable: true, + log_level: Some(log::Level::Error), + ..Flags::default() + } + ); + } + + #[test] fn task_subcommand_empty() { let r = flags_from_vec(svec!["deno", "task"]); assert_eq!( |