@@ -56,33 +56,40 @@ function fishOptionFlags(options: Command["options"], wantsValue: boolean): stri
5656 } ) ;
5757}
5858
59+ function collectFishOptionFlags ( program : Command , wantsValue : boolean ) : string [ ] {
60+ const flags = new Set < string > ( ) ;
61+ const visit = ( cmd : Command ) => {
62+ for ( const flag of fishOptionFlags ( cmd . options , wantsValue ) ) {
63+ flags . add ( flag ) ;
64+ }
65+ for ( const child of cmd . commands ) {
66+ visit ( child ) ;
67+ }
68+ } ;
69+ visit ( program ) ;
70+ return [ ...flags ] ;
71+ }
72+
5973function generateFishPathHelper ( program : Command , rootCmd : string ) : string {
60- const rootValueOptions = fishOptionFlags ( program . options , true ) ;
61- const rootBooleanOptions = fishOptionFlags ( program . options , false ) ;
74+ const valueOptions = collectFishOptionFlags ( program , true ) ;
6275 return `
6376function __${ rootCmd } _command_path_matches
6477 set -l tokens (commandline -opc)
6578 set -e tokens[1]
66- set -l root_value_options ${ fishWords ( rootValueOptions ) }
67- set -l root_boolean_options ${ fishWords ( rootBooleanOptions ) }
79+ set -l value_options ${ fishWords ( valueOptions ) }
6880 set -l command_tokens
6981 set -l skip_next 0
7082 for token in $tokens
7183 if test $skip_next -eq 1
7284 set skip_next 0
7385 continue
7486 end
75- if test (count $command_tokens) -eq 0
76- set -l flag (string split -m1 "=" -- $token)[1]
77- if contains -- $flag $root_boolean_options
78- continue
79- end
80- if contains -- $flag $root_value_options
81- if not string match -q -- "*=*" $token
82- set skip_next 1
83- end
84- continue
87+ set -l flag (string split -m1 "=" -- $token)[1]
88+ if contains -- $flag $value_options
89+ if not string match -q -- "*=*" $token
90+ set skip_next 1
8591 end
92+ continue
8693 end
8794 if string match -q -- "-*" $token
8895 continue
0 commit comments