1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

fix(task): subcommand parser skips global args (#15297)

This commit is contained in:
Cre3per 2022-08-10 17:55:34 +02:00 committed by GitHub
parent bdd8ddbe4c
commit afc29c28ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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() {
@ -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"]);