@@ -34,6 +34,11 @@ extension CompletionScriptTests {
34
34
}
35
35
36
36
struct Base : ParsableCommand {
37
+ static var configuration = CommandConfiguration (
38
+ commandName: " base-test " ,
39
+ subcommands: [ SubCommand . self]
40
+ )
41
+
37
42
@Option ( help: " The user's name. " ) var name : String
38
43
@Option ( ) var kind : Kind
39
44
@Option ( completion: . list( [ " 1 " , " 2 " , " 3 " ] ) ) var otherKind : Kind
@@ -43,6 +48,12 @@ extension CompletionScriptTests {
43
48
@Option ( completion: . list( [ " a " , " b " , " c " ] ) ) var path3 : Path
44
49
45
50
@Flag ( help: . hidden) var verbose = false
51
+
52
+ struct SubCommand : ParsableCommand {
53
+ static var configuration = CommandConfiguration (
54
+ commandName: " sub-command "
55
+ )
56
+ }
46
57
}
47
58
48
59
func testBase_Zsh( ) throws {
@@ -138,12 +149,12 @@ extension CompletionScriptTests {
138
149
}
139
150
140
151
private let zshBaseCompletions = """
141
- #compdef base
152
+ #compdef base-test
142
153
local context state state_descr line
143
- _base_commandname =$words[1]
154
+ _base_test_commandname =$words[1]
144
155
typeset -A opt_args
145
156
146
- _base() {
157
+ _base-test () {
147
158
integer ret=1
148
159
local -a args
149
160
args+=(
@@ -154,6 +165,50 @@ _base() {
154
165
'--path2:path2:_files'
155
166
'--path3:path3:(a b c)'
156
167
'(-h --help)'{-h,--help}'[Show help information.]'
168
+ '(-): :->command'
169
+ '(-)*:: :->arg'
170
+ )
171
+ _arguments -w -s -S $args[@] && ret=0
172
+ case $state in
173
+ (command)
174
+ local subcommands
175
+ subcommands=(
176
+ 'sub-command:'
177
+ 'help:Show subcommand help information.'
178
+ )
179
+ _describe " subcommand " subcommands
180
+ ;;
181
+ (arg)
182
+ case ${words[1]} in
183
+ (sub-command)
184
+ _base-test_sub-command
185
+ ;;
186
+ (help)
187
+ _base-test_help
188
+ ;;
189
+ esac
190
+ ;;
191
+ esac
192
+
193
+ return ret
194
+ }
195
+
196
+ _base-test_sub-command() {
197
+ integer ret=1
198
+ local -a args
199
+ args+=(
200
+ '(-h --help)'{-h,--help}'[Show help information.]'
201
+ )
202
+ _arguments -w -s -S $args[@] && ret=0
203
+
204
+ return ret
205
+ }
206
+
207
+ _base-test_help() {
208
+ integer ret=1
209
+ local -a args
210
+ args+=(
211
+ ':subcommands:'
157
212
)
158
213
_arguments -w -s -S $args[@] && ret=0
159
214
@@ -166,17 +221,17 @@ _custom_completion() {
166
221
_describe '' completions
167
222
}
168
223
169
- _base
224
+ _base-test
170
225
"""
171
226
172
227
private let bashBaseCompletions = """
173
228
#!/bin/bash
174
229
175
- _base () {
230
+ _base_test () {
176
231
cur= " ${COMP_WORDS[COMP_CWORD]} "
177
232
prev= " ${COMP_WORDS[COMP_CWORD-1]} "
178
233
COMPREPLY=()
179
- opts= " --name --kind --other-kind --path1 --path2 --path3 -h --help "
234
+ opts= " --name --kind --other-kind --path1 --path2 --path3 -h --help sub-command help "
180
235
if [[ $COMP_CWORD == " 1 " ]]; then
181
236
COMPREPLY=( $(compgen -W " $opts " -- " $cur " ) )
182
237
return
@@ -215,11 +270,37 @@ _base() {
215
270
return
216
271
;;
217
272
esac
273
+ case ${COMP_WORDS[1]} in
274
+ (sub-command)
275
+ _base_test_sub-command 2
276
+ return
277
+ ;;
278
+ (help)
279
+ _base_test_help 2
280
+ return
281
+ ;;
282
+ esac
283
+ COMPREPLY=( $(compgen -W " $opts " -- " $cur " ) )
284
+ }
285
+ _base_test_sub_command() {
286
+ opts= " -h --help "
287
+ if [[ $COMP_CWORD == " $1 " ]]; then
288
+ COMPREPLY=( $(compgen -W " $opts " -- " $cur " ) )
289
+ return
290
+ fi
291
+ COMPREPLY=( $(compgen -W " $opts " -- " $cur " ) )
292
+ }
293
+ _base_test_help() {
294
+ opts= " "
295
+ if [[ $COMP_CWORD == " $1 " ]]; then
296
+ COMPREPLY=( $(compgen -W " $opts " -- " $cur " ) )
297
+ return
298
+ fi
218
299
COMPREPLY=( $(compgen -W " $opts " -- " $cur " ) )
219
300
}
220
301
221
302
222
- complete -F _base base
303
+ complete -F _base_test base-test
223
304
"""
224
305
225
306
private let zshEscapedCompletion = """
@@ -252,7 +333,7 @@ _escaped-command
252
333
253
334
private let fishBaseCompletions = """
254
335
# A function which filters options which starts with " - " from $argv.
255
- function _swift_base_preprocessor
336
+ function _swift_base-test_preprocessor
256
337
set -l results
257
338
for i in (seq (count $argv))
258
339
switch (echo $argv[$i] | string sub -l 1)
@@ -263,8 +344,8 @@ function _swift_base_preprocessor
263
344
end
264
345
end
265
346
266
- function _swift_base_using_command
267
- set -l currentCommands (_swift_base_preprocessor (commandline -opc))
347
+ function _swift_base-test_using_command
348
+ set -l currentCommands (_swift_base-test_preprocessor (commandline -opc))
268
349
set -l expectedCommands (string split " " $argv[1])
269
350
set -l subcommands (string split " " $argv[2])
270
351
if [ (count $currentCommands) -ge (count $expectedCommands) ]
@@ -288,13 +369,16 @@ function _swift_base_using_command
288
369
return 1
289
370
end
290
371
291
- complete -c base -n '_swift_base_using_command \" base \" ' -l name -d 'The user \\ \' s name.'
292
- complete -c base -n '_swift_base_using_command \" base \" ' -l kind -r -f -k -a 'one two custom-three'
293
- complete -c base -n '_swift_base_using_command \" base \" ' -l other-kind -r -f -k -a '1 2 3'
294
- complete -c base -n '_swift_base_using_command \" base \" ' -l path1 -r -f -a '(for i in *.{}; echo $i;end)'
295
- complete -c base -n '_swift_base_using_command \" base \" ' -l path2 -r -f -a '(for i in *.{}; echo $i;end)'
296
- complete -c base -n '_swift_base_using_command \" base \" ' -l path3 -r -f -k -a 'a b c'
297
- complete -c base -n '_swift_base_using_command \" base \" ' -s h -l help -d 'Show help information.'
372
+ complete -c base-test -n '_swift_base-test_using_command " base-test sub-command " ' -s h -l help -d 'Show help information.'
373
+ complete -c base-test -n '_swift_base-test_using_command " base-test " " sub-command help " ' -l name -d 'The user \\ \' s name.'
374
+ complete -c base-test -n '_swift_base-test_using_command " base-test " " sub-command help " ' -l kind -r -f -k -a 'one two custom-three'
375
+ complete -c base-test -n '_swift_base-test_using_command " base-test " " sub-command help " ' -l other-kind -r -f -k -a '1 2 3'
376
+ complete -c base-test -n '_swift_base-test_using_command " base-test " " sub-command help " ' -l path1 -r -f -a '(for i in *.{}; echo $i;end)'
377
+ complete -c base-test -n '_swift_base-test_using_command " base-test " " sub-command help " ' -l path2 -r -f -a '(for i in *.{}; echo $i;end)'
378
+ complete -c base-test -n '_swift_base-test_using_command " base-test " " sub-command help " ' -l path3 -r -f -k -a 'a b c'
379
+ complete -c base-test -n '_swift_base-test_using_command " base-test " " sub-command help " ' -s h -l help -d 'Show help information.'
380
+ complete -c base-test -n '_swift_base-test_using_command " base-test " " sub-command help " ' -f -a 'sub-command' -d ''
381
+ complete -c base-test -n '_swift_base-test_using_command " base-test " " sub-command help " ' -f -a 'help' -d 'Show subcommand help information.'
298
382
"""
299
383
300
384
// MARK: - Test Hidden Subcommand
0 commit comments