@@ -56,33 +56,40 @@ function fishOptionFlags(options: Command["options"], wantsValue: boolean): stri
|
56 | 56 | }); |
57 | 57 | } |
58 | 58 | |
| 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 | + |
59 | 73 | function 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); |
62 | 75 | return ` |
63 | 76 | function __${rootCmd}_command_path_matches |
64 | 77 | set -l tokens (commandline -opc) |
65 | 78 | 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)} |
68 | 80 | set -l command_tokens |
69 | 81 | set -l skip_next 0 |
70 | 82 | for token in $tokens |
71 | 83 | if test $skip_next -eq 1 |
72 | 84 | set skip_next 0 |
73 | 85 | continue |
74 | 86 | 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 |
85 | 91 | end |
| 92 | + continue |
86 | 93 | end |
87 | 94 | if string match -q -- "-*" $token |
88 | 95 | continue |
|