Skip to content

Commit 8607918

Browse files
authored
feat: make InitDefaultCompletionCmd public (#1467)
* feat: make InitDefaultCompletionCmd public * PR comments * Update man_docs_test.go * Update README.md
1 parent 2169adb commit 8607918

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
996996
// initialize help at the last point to allow for user overriding
997997
c.InitDefaultHelpCmd()
998998
// initialize completion at the last point to allow for user overriding
999-
c.initDefaultCompletionCmd()
999+
c.InitDefaultCompletionCmd()
10001000

10011001
args := c.args
10021002

completions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,12 @@ func checkIfFlagCompletion(finalCmd *Command, args []string, lastArg string) (*p
645645
return flag, trimmedArgs, lastArg, nil
646646
}
647647

648-
// initDefaultCompletionCmd adds a default 'completion' command to c.
648+
// InitDefaultCompletionCmd adds a default 'completion' command to c.
649649
// This function will do nothing if any of the following is true:
650650
// 1- the feature has been explicitly disabled by the program,
651651
// 2- c has no subcommands (to avoid creating one),
652652
// 3- c already has a 'completion' command provided by the program.
653-
func (c *Command) initDefaultCompletionCmd() {
653+
func (c *Command) InitDefaultCompletionCmd() {
654654
if c.CompletionOptions.DisableDefaultCmd || !c.HasSubCommands() {
655655
return
656656
}

doc/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
## Options
99
### `DisableAutoGenTag`
10+
1011
You may set `cmd.DisableAutoGenTag = true`
1112
to _entirely_ remove the auto generated string "Auto generated by spf13/cobra..."
1213
from any documentation source.
14+
15+
### `InitDefaultCompletionCmd`
16+
17+
You may call `cmd.InitDefaultCompletionCmd()` to document the default autocompletion command.

0 commit comments

Comments
 (0)