diff --git a/completions.go b/completions.go index 5788674f..ad7b6d0a 100644 --- a/completions.go +++ b/completions.go @@ -18,6 +18,7 @@ import ( "fmt" "os" "regexp" + "strconv" "strings" "sync" @@ -212,7 +213,12 @@ func (c *Command) initCompleteCmd(args []string) { // 2- Even without completions, we need to print the directive } - noDescriptions := cmd.CalledAs() == ShellCompNoDescRequestCmd || getEnvConfig(cmd, configEnvVarSuffixDescriptions) == configEnvVarDescriptionsOff + noDescriptions := cmd.CalledAs() == ShellCompNoDescRequestCmd + if !noDescriptions { + if doDescriptions, err := strconv.ParseBool(getEnvConfig(cmd, configEnvVarSuffixDescriptions)); err == nil { + noDescriptions = !doDescriptions + } + } noActiveHelp := GetActiveHelpConfig(finalCmd) == activeHelpGlobalDisable out := finalCmd.OutOrStdout() for _, comp := range completions { @@ -905,7 +911,6 @@ func CompErrorln(msg string) { const ( configEnvVarGlobalPrefix = "COBRA" configEnvVarSuffixDescriptions = "COMPLETION_DESCRIPTIONS" - configEnvVarDescriptionsOff = "off" ) var configEnvVarPrefixSubstRegexp = regexp.MustCompile(`[^A-Z0-9_]`) diff --git a/site/content/completions/_index.md b/site/content/completions/_index.md index b2b8017c..02257ade 100644 --- a/site/content/completions/_index.md +++ b/site/content/completions/_index.md @@ -394,7 +394,7 @@ $ helm completion [tab][tab] bash fish powershell zsh ``` -Setting the `_COMPLETION_DESCRIPTIONS` environment variable (falling back to `COBRA_COMPLETION_DESCRIPTIONS` if empty or not set) to `off` achieves the same. `` is the name of your program with all non-ASCII-alphanumeric characters replaced by `_`. +Setting the `_COMPLETION_DESCRIPTIONS` environment variable (falling back to `COBRA_COMPLETION_DESCRIPTIONS` if empty or not set) to a [falsey value](https://pkg.go.dev/strconv#ParseBool) achieves the same. `` is the name of your program with all non-ASCII-alphanumeric characters replaced by `_`. ## Bash completions