mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
feat: make InitDefaultCompletionCmd public (#1467)
* feat: make InitDefaultCompletionCmd public * PR comments * Update man_docs_test.go * Update README.md
This commit is contained in:
parent
2169adb574
commit
860791844e
3 changed files with 8 additions and 3 deletions
|
@ -996,7 +996,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||||
// initialize help at the last point to allow for user overriding
|
// initialize help at the last point to allow for user overriding
|
||||||
c.InitDefaultHelpCmd()
|
c.InitDefaultHelpCmd()
|
||||||
// initialize completion at the last point to allow for user overriding
|
// initialize completion at the last point to allow for user overriding
|
||||||
c.initDefaultCompletionCmd()
|
c.InitDefaultCompletionCmd()
|
||||||
|
|
||||||
args := c.args
|
args := c.args
|
||||||
|
|
||||||
|
|
|
@ -645,12 +645,12 @@ func checkIfFlagCompletion(finalCmd *Command, args []string, lastArg string) (*p
|
||||||
return flag, trimmedArgs, lastArg, nil
|
return flag, trimmedArgs, lastArg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// initDefaultCompletionCmd adds a default 'completion' command to c.
|
// InitDefaultCompletionCmd adds a default 'completion' command to c.
|
||||||
// This function will do nothing if any of the following is true:
|
// This function will do nothing if any of the following is true:
|
||||||
// 1- the feature has been explicitly disabled by the program,
|
// 1- the feature has been explicitly disabled by the program,
|
||||||
// 2- c has no subcommands (to avoid creating one),
|
// 2- c has no subcommands (to avoid creating one),
|
||||||
// 3- c already has a 'completion' command provided by the program.
|
// 3- c already has a 'completion' command provided by the program.
|
||||||
func (c *Command) initDefaultCompletionCmd() {
|
func (c *Command) InitDefaultCompletionCmd() {
|
||||||
if c.CompletionOptions.DisableDefaultCmd || !c.HasSubCommands() {
|
if c.CompletionOptions.DisableDefaultCmd || !c.HasSubCommands() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
### `DisableAutoGenTag`
|
### `DisableAutoGenTag`
|
||||||
|
|
||||||
You may set `cmd.DisableAutoGenTag = true`
|
You may set `cmd.DisableAutoGenTag = true`
|
||||||
to _entirely_ remove the auto generated string "Auto generated by spf13/cobra..."
|
to _entirely_ remove the auto generated string "Auto generated by spf13/cobra..."
|
||||||
from any documentation source.
|
from any documentation source.
|
||||||
|
|
||||||
|
### `InitDefaultCompletionCmd`
|
||||||
|
|
||||||
|
You may call `cmd.InitDefaultCompletionCmd()` to document the default autocompletion command.
|
||||||
|
|
Loading…
Reference in a new issue