@@ -268,3 +268,114 @@ complete -c base -n '_swift_base_using_command base' -f -r -l path3
268
268
complete -c base -n '_swift_base_using_command base --path3' -f -k -a 'a b c'
269
269
complete -c base -n '_swift_base_using_command base' -f -s h -l help -d 'Show help information.'
270
270
"""
271
+
272
+ // MARK: - Test Hidden Subcommand
273
+ struct Parent : ParsableCommand {
274
+ static var configuration = CommandConfiguration ( subcommands: [ HiddenChild . self] )
275
+ }
276
+
277
+ struct HiddenChild : ParsableCommand {
278
+ static var configuration = CommandConfiguration ( shouldDisplay: false )
279
+ }
280
+
281
+ extension CompletionScriptTests {
282
+ func testHiddenSubcommand_Zsh( ) throws {
283
+ let script1 = try CompletionsGenerator ( command: Parent . self, shell: . zsh)
284
+ . generateCompletionScript ( )
285
+ XCTAssertEqual ( zshHiddenCompletion, script1)
286
+
287
+ let script2 = try CompletionsGenerator ( command: Parent . self, shellName: " zsh " )
288
+ . generateCompletionScript ( )
289
+ XCTAssertEqual ( zshHiddenCompletion, script2)
290
+
291
+ let script3 = Parent . completionScript ( for: . zsh)
292
+ XCTAssertEqual ( zshHiddenCompletion, script3)
293
+ }
294
+
295
+ func testHiddenSubcommand_Bash( ) throws {
296
+ let script1 = try CompletionsGenerator ( command: Parent . self, shell: . bash)
297
+ . generateCompletionScript ( )
298
+ XCTAssertEqual ( bashHiddenCompletion, script1)
299
+
300
+ let script2 = try CompletionsGenerator ( command: Parent . self, shellName: " bash " )
301
+ . generateCompletionScript ( )
302
+ XCTAssertEqual ( bashHiddenCompletion, script2)
303
+
304
+ let script3 = Parent . completionScript ( for: . bash)
305
+ XCTAssertEqual ( bashHiddenCompletion, script3)
306
+ }
307
+
308
+ func testHiddenSubcommand_Fish( ) throws {
309
+ let script1 = try CompletionsGenerator ( command: Parent . self, shell: . fish)
310
+ . generateCompletionScript ( )
311
+ XCTAssertEqual ( fishHiddenCompletion, script1)
312
+
313
+ let script2 = try CompletionsGenerator ( command: Parent . self, shellName: " fish " )
314
+ . generateCompletionScript ( )
315
+ XCTAssertEqual ( fishHiddenCompletion, script2)
316
+
317
+ let script3 = Parent . completionScript ( for: . fish)
318
+ XCTAssertEqual ( fishHiddenCompletion, script3)
319
+ }
320
+ }
321
+
322
+ let zshHiddenCompletion = """
323
+ #compdef parent
324
+ local context state state_descr line
325
+ _parent_commandname=$words[1]
326
+ typeset -A opt_args
327
+
328
+ _parent() {
329
+ integer ret=1
330
+ local -a args
331
+ args+=(
332
+ '(-h --help)'{-h,--help}'[Show help information.]'
333
+ )
334
+ _arguments -w -s -S $args[@] && ret=0
335
+
336
+ return ret
337
+ }
338
+
339
+
340
+ _custom_completion() {
341
+ local completions=( " ${(@f)$($*)} " )
342
+ _describe '' completions
343
+ }
344
+
345
+ _parent
346
+ """
347
+
348
+ let bashHiddenCompletion = """
349
+ #!/bin/bash
350
+
351
+ _parent() {
352
+ cur= " ${COMP_WORDS[COMP_CWORD]} "
353
+ prev= " ${COMP_WORDS[COMP_CWORD-1]} "
354
+ COMPREPLY=()
355
+ opts= " -h --help "
356
+ if [[ $COMP_CWORD == " 1 " ]]; then
357
+ COMPREPLY=( $(compgen -W " $opts " -- " $cur " ) )
358
+ return
359
+ fi
360
+ COMPREPLY=( $(compgen -W " $opts " -- " $cur " ) )
361
+ }
362
+
363
+
364
+ complete -F _parent parent
365
+ """
366
+
367
+ let fishHiddenCompletion = """
368
+ function _swift_parent_using_command
369
+ set -l cmd (commandline -opc)
370
+ if [ (count $cmd) -eq (count $argv) ]
371
+ for i in (seq (count $argv))
372
+ if [ $cmd[$i] != $argv[$i] ]
373
+ return 1
374
+ end
375
+ end
376
+ return 0
377
+ end
378
+ return 1
379
+ end
380
+ complete -c parent -n '_swift_parent_using_command parent' -f -s h -l help -d 'Show help information.'
381
+ """
0 commit comments