Skip to content

Commit

Permalink
fix(task): subcommand parser skips global args (denoland#15297)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cre3per committed Aug 10, 2022
1 parent bdd8ddb commit afc29c2
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -5764,6 +5765,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"]);
Expand Down

0 comments on commit afc29c2

Please sign in to comment.