You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve zsh completion for repeatable options (#614)
Some commands allow an option to be repeated to provide multiple values.
For example, ssh allows the -L flag to be repeated to establish multiple
port forwardings.
ArgumentParser supports this style when the Option value is an Array
and the parsingStrategy is ArrayParsingStrategy.singleValue or
.unconditionalSingleValue.
Without this patch, ArgumentParser generates a zsh completion script
that does not handle repeatable options correctly. The generated script
suppresses completion of any option after that option's first use, even
if the option is repeatable.
With this patch, ArgumentParser generates a zsh completion script that
allows a repeatable option to be completed each time it is used.
The relevant zsh _arguments syntax is documented here:
https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Completion-Functions
Specifically, a repeatable option's optspec needs to start with '*'.
Furthermore, a repeatable argument must not list itself or its synonyms
in its own parenthesized suppression list. (This is not clearly
documented.)
fixes#564
* Add test for repeated flag completions
/// - returns: `true` if I'm an option and can be tab-completed multiple times in one command line. For example, `ssh` allows the `-L` option to be given multiple times, to establish multiple port forwardings.
171
+
privatevarisRepeatableOption:Bool{
172
+
guard
173
+
case .named(_)= kind,
174
+
help.options.contains(.isRepeating)
175
+
else{returnfalse}
176
+
177
+
switch parsingStrategy {
178
+
case.default,.unconditional:returntrue
179
+
default:returnfalse
180
+
}
181
+
}
182
+
168
183
/// Returns the zsh "action" for an argument completion string.
0 commit comments