File tree 2 files changed +18
-0
lines changed 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,8 @@ type CompletionOptions struct {
93
93
// DisableDescriptions turns off all completion descriptions for shells
94
94
// that support them
95
95
DisableDescriptions bool
96
+ // HiddenDefaultCmd makes the default 'completion' command hidden
97
+ HiddenDefaultCmd bool
96
98
}
97
99
98
100
// NoFileCompletions can be used to disable file completion for commands that should
@@ -605,6 +607,7 @@ See each sub-command's help for details on how to use the generated script.
605
607
` , c .Root ().Name ()),
606
608
Args : NoArgs ,
607
609
ValidArgsFunction : NoFileCompletions ,
610
+ Hidden : c .CompletionOptions .HiddenDefaultCmd ,
608
611
}
609
612
c .AddCommand (completionCmd )
610
613
Original file line number Diff line number Diff line change @@ -2398,6 +2398,21 @@ func TestDefaultCompletionCmd(t *testing.T) {
2398
2398
rootCmd .CompletionOptions .DisableDescriptions = false
2399
2399
// Remove completion command for the next test
2400
2400
removeCompCmd (rootCmd )
2401
+
2402
+ // Test that the 'completion' command can be hidden
2403
+ rootCmd .CompletionOptions .HiddenDefaultCmd = true
2404
+ assertNoErr (t , rootCmd .Execute ())
2405
+ compCmd , _ , err = rootCmd .Find ([]string {compCmdName })
2406
+ if err != nil {
2407
+ t .Errorf ("Unexpected error: %v" , err )
2408
+ }
2409
+ if compCmd .Hidden == false {
2410
+ t .Error ("Default 'completion' command should be hidden but it is not" )
2411
+ }
2412
+ // Re-enable for next test
2413
+ rootCmd .CompletionOptions .HiddenDefaultCmd = false
2414
+ // Remove completion command for the next test
2415
+ removeCompCmd (rootCmd )
2401
2416
}
2402
2417
2403
2418
func TestCompleteCompletion (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments