From 2c46d197aecafb557790d6070b320b018e91276f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 19 Jun 2023 23:24:23 +0300 Subject: [PATCH] Add env var config for disabling descriptions --- completions.go | 10 +++++++--- site/content/completions/_index.md | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/completions.go b/completions.go index 531a67cea3..5657bbe96c 100644 --- a/completions.go +++ b/completions.go @@ -217,7 +217,7 @@ func (c *Command) initCompleteCmd(args []string) { // 2- Even without completions, we need to print the directive } - noDescriptions := (cmd.CalledAs() == ShellCompNoDescRequestCmd) + noDescriptions := cmd.CalledAs() == ShellCompNoDescRequestCmd || GetEnvConfig(cmd, configEnvVarSuffixDescriptions) == configEnvVarDescriptionsOff for _, comp := range completions { if GetActiveHelpConfig(finalCmd) == activeHelpGlobalDisable { // Remove all activeHelp entries in this case @@ -897,8 +897,12 @@ func CompErrorln(msg string) { CompError(fmt.Sprintf("%s\n", msg)) } -// configEnvVarGlobalPrefix should not be changed: users will be using it explicitly. -const configEnvVarGlobalPrefix = "COBRA" +// These values should not be changed: users will be using them explicitly. +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 4efad2907b..b2b8017c68 100644 --- a/site/content/completions/_index.md +++ b/site/content/completions/_index.md @@ -393,6 +393,9 @@ $ source <(helm completion bash --no-descriptions) $ 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 `_`. + ## Bash completions ### Dependencies