Skip to content

Commit 750a170

Browse files
authored
Allow zsh repeating positionals to be completed multiple times. (#777)
Signed-off-by: Ross Goldberg <[email protected]>
1 parent 151e5ec commit 750a170

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ extension [ParsableCommand.Type] {
143143
let line: String
144144
switch arg.names.count {
145145
case 0:
146-
line = ""
146+
line = arg.help.options.contains(.isRepeating) ? "*" : ""
147147
case 1:
148148
line = """
149-
\(arg.isRepeatableOption ? "*" : "")\(arg.names[0].synopsisString)\(arg.zshCompletionAbstract)
149+
\(arg.isRepeatingOption ? "*" : "")\(arg.names[0].synopsisString)\(arg.zshCompletionAbstract)
150150
"""
151151
default:
152152
let synopses = arg.names.map { $0.synopsisString }
153153
line = """
154-
\(arg.isRepeatableOption ? "*" : "(\(synopses.joined(separator: " ")))")'\
154+
\(arg.isRepeatingOption ? "*" : "(\(synopses.joined(separator: " ")))")'\
155155
{\(synopses.joined(separator: ","))}\
156156
'\(arg.zshCompletionAbstract)
157157
"""
@@ -251,9 +251,9 @@ extension String {
251251
}
252252

253253
extension ArgumentDefinition {
254-
/// - returns: `true` if `self` is an option and can be tab-completed multiple times in one command line.
254+
/// - returns: `true` if `self` is a flag or an option and can be tab-completed multiple times in one command line.
255255
/// For example, `ssh` allows the `-L` option to be given multiple times, to establish multiple port forwardings.
256-
fileprivate var isRepeatableOption: Bool {
256+
fileprivate var isRepeatingOption: Bool {
257257
guard
258258
case .named(_) = kind,
259259
help.options.contains(.isRepeating)

Tests/ArgumentParserExampleTests/Snapshots/testMathZshCompletionScript().zsh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ _math_add() {
7373
local -i ret=1
7474
local -ar arg_specs=(
7575
'(--hex-output -x)'{--hex-output,-x}'[Use hexadecimal notation for the result.]'
76-
':values:'
76+
'*:values:'
7777
'--version[Show the version.]'
7878
'(-h --help)'{-h,--help}'[Show help information.]'
7979
)
@@ -86,7 +86,7 @@ _math_multiply() {
8686
local -i ret=1
8787
local -ar arg_specs=(
8888
'(--hex-output -x)'{--hex-output,-x}'[Use hexadecimal notation for the result.]'
89-
':values:'
89+
'*:values:'
9090
'--version[Show the version.]'
9191
'(-h --help)'{-h,--help}'[Show help information.]'
9292
)
@@ -130,7 +130,7 @@ _math_stats_average() {
130130
local -ar __math_stats_average_kind=('mean' 'median' 'mode')
131131
local -ar arg_specs=(
132132
'--kind[The kind of average to provide.]:kind:{__math_complete "${__math_stats_average_kind[@]}"}'
133-
':values:'
133+
'*:values:'
134134
'--version[Show the version.]'
135135
'(-h --help)'{-h,--help}'[Show help information.]'
136136
)
@@ -142,7 +142,7 @@ _math_stats_average() {
142142
_math_stats_stdev() {
143143
local -i ret=1
144144
local -ar arg_specs=(
145-
':values:'
145+
'*:values:'
146146
'--version[Show the version.]'
147147
'(-h --help)'{-h,--help}'[Show help information.]'
148148
)
@@ -158,7 +158,7 @@ _math_stats_quantiles() {
158158
':one-of-four:{__math_complete "${math_stats_quantiles_one_of_four[@]}"}'
159159
':custom-arg:{__math_custom_complete ---completion stats quantiles -- customArg "${current_word_index}" "$(__math_cursor_index_in_current_word)"}'
160160
':custom-deprecated-arg:{__math_custom_complete ---completion stats quantiles -- customDeprecatedArg}'
161-
':values:'
161+
'*:values:'
162162
'--file:file:_files -g '\''*.txt *.md'\'''
163163
'--directory:directory:_files -/'
164164
'--shell:shell:{local -a list;list=(${(f)"$(head -100 /usr/share/dict/words | tail -50)"});_describe -V "" list}'
@@ -175,7 +175,7 @@ _math_stats_quantiles() {
175175
_math_help() {
176176
local -i ret=1
177177
local -ar arg_specs=(
178-
':subcommands:'
178+
'*:subcommands:'
179179
'--version[Show the version.]'
180180
)
181181
_arguments -w -s -S : "${arg_specs[@]}" && ret=0

Tests/ArgumentParserUnitTests/Snapshots/testBase_Zsh().zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ _base-test_escaped-command() {
109109
_base-test_help() {
110110
local -i ret=1
111111
local -ar arg_specs=(
112-
':subcommands:'
112+
'*:subcommands:'
113113
)
114114
_arguments -w -s -S : "${arg_specs[@]}" && ret=0
115115

0 commit comments

Comments
 (0)