@@ -554,7 +554,15 @@ pub fn flags_from_vec(args: Vec<String>) -> clap::Result<Flags> {
554
554
Some ( ( "lsp" , m) ) => lsp_parse ( & mut flags, m) ,
555
555
Some ( ( "repl" , m) ) => repl_parse ( & mut flags, m) ,
556
556
Some ( ( "run" , m) ) => run_parse ( & mut flags, m) ,
557
- Some ( ( "task" , m) ) => task_parse ( & mut flags, m, & args) ,
557
+ Some ( ( "task" , m) ) => task_parse (
558
+ & mut flags,
559
+ m,
560
+ // temporary workaround until https://github.com/clap-rs/clap/issues/1538 is fixed
561
+ & args[ args
562
+ . iter ( )
563
+ . position ( |el| el == matches. subcommand_name ( ) . unwrap ( ) )
564
+ . unwrap ( ) ..] ,
565
+ ) ,
558
566
Some ( ( "test" , m) ) => test_parse ( & mut flags, m) ,
559
567
Some ( ( "types" , m) ) => types_parse ( & mut flags, m) ,
560
568
Some ( ( "uninstall" , m) ) => uninstall_parse ( & mut flags, m) ,
@@ -2561,6 +2569,9 @@ fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
2561
2569
flags. subcommand = DenoSubcommand :: Run ( RunFlags { script } ) ;
2562
2570
}
2563
2571
2572
+ /// raw_args is the subcommand's command line, eg. for the deno invocation
2573
+ /// `deno task echo`
2574
+ /// raw_args has value ["task", "echo"]
2564
2575
fn task_parse (
2565
2576
flags : & mut Flags ,
2566
2577
matches : & clap:: ArgMatches ,
@@ -2582,8 +2593,6 @@ fn task_parse(
2582
2593
}
2583
2594
2584
2595
if let Some ( mut index) = matches. index_of ( "task_name_and_args" ) {
2585
- index += 1 ; // skip `task`
2586
-
2587
2596
// temporary workaround until https://github.com/clap-rs/clap/issues/1538 is fixed
2588
2597
while index < raw_args. len ( ) {
2589
2598
match raw_args[ index] . as_str ( ) {
@@ -5764,6 +5773,25 @@ mod tests {
5764
5773
) ;
5765
5774
}
5766
5775
5776
+ #[ test]
5777
+ fn task_with_global_flags ( ) {
5778
+ // can fail if the custom parser in task_parse() starts at the wrong index
5779
+ let r =
5780
+ flags_from_vec ( svec ! [ "deno" , "--quiet" , "--unstable" , "task" , "build" ] ) ;
5781
+ assert_eq ! (
5782
+ r. unwrap( ) ,
5783
+ Flags {
5784
+ subcommand: DenoSubcommand :: Task ( TaskFlags {
5785
+ cwd: None ,
5786
+ task: "build" . to_string( ) ,
5787
+ } ) ,
5788
+ unstable: true ,
5789
+ log_level: Some ( log:: Level :: Error ) ,
5790
+ ..Flags :: default ( )
5791
+ }
5792
+ ) ;
5793
+ }
5794
+
5767
5795
#[ test]
5768
5796
fn task_subcommand_empty ( ) {
5769
5797
let r = flags_from_vec ( svec ! [ "deno" , "task" ] ) ;
0 commit comments