From 860791844ed3a2e544a9b9bbbcb14144a948ad20 Mon Sep 17 00:00:00 2001 From: Gustavo Bazan Date: Tue, 11 Oct 2022 00:06:30 +0100 Subject: [PATCH] feat: make InitDefaultCompletionCmd public (#1467) * feat: make InitDefaultCompletionCmd public * PR comments * Update man_docs_test.go * Update README.md --- command.go | 2 +- completions.go | 4 ++-- doc/README.md | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/command.go b/command.go index ad26507..9d5e9cf 100644 --- a/command.go +++ b/command.go @@ -996,7 +996,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) { // initialize help at the last point to allow for user overriding c.InitDefaultHelpCmd() // initialize completion at the last point to allow for user overriding - c.initDefaultCompletionCmd() + c.InitDefaultCompletionCmd() args := c.args diff --git a/completions.go b/completions.go index 122d752..e8a0206 100644 --- a/completions.go +++ b/completions.go @@ -645,12 +645,12 @@ func checkIfFlagCompletion(finalCmd *Command, args []string, lastArg string) (*p 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: // 1- the feature has been explicitly disabled by the program, // 2- c has no subcommands (to avoid creating one), // 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() { return } diff --git a/doc/README.md b/doc/README.md index 6ea4eb6..8e07baa 100644 --- a/doc/README.md +++ b/doc/README.md @@ -7,6 +7,11 @@ ## Options ### `DisableAutoGenTag` + You may set `cmd.DisableAutoGenTag = true` to _entirely_ remove the auto generated string "Auto generated by spf13/cobra..." from any documentation source. + +### `InitDefaultCompletionCmd` + +You may call `cmd.InitDefaultCompletionCmd()` to document the default autocompletion command.