Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Oct 24, 2023
1 parent 025541a commit 4474cf6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 9 additions & 4 deletions completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ 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
noActiveHelp := GetActiveHelpConfig(finalCmd) == activeHelpGlobalDisable

Check failure on line 221 in completions.go

View workflow job for this annotation

GitHub Actions / ubuntu | 1.17.x

noActiveHelp declared but not used

Check failure on line 221 in completions.go

View workflow job for this annotation

GitHub Actions / macOS | 1.17.x

noActiveHelp declared but not used
out := finalCmd.OutOrStdout()

Check failure on line 222 in completions.go

View workflow job for this annotation

GitHub Actions / ubuntu | 1.17.x

out declared but not used

Check failure on line 222 in completions.go

View workflow job for this annotation

GitHub Actions / macOS | 1.17.x

out declared but not used
for _, comp := range completions {
if GetActiveHelpConfig(finalCmd) == activeHelpGlobalDisable {
// Remove all activeHelp entries in this case
Expand Down Expand Up @@ -825,7 +827,6 @@ to your powershell profile.
return cmd.Root().GenPowerShellCompletion(out)
}
return cmd.Root().GenPowerShellCompletionWithDesc(out)

},
}
if haveNoDescFlag {
Expand Down Expand Up @@ -897,8 +898,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_]`)

Expand Down
5 changes: 4 additions & 1 deletion site/content/completions/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ To tell Cobra to mark the default `completion` command as *hidden*:
rootCmd.CompletionOptions.HiddenDefaultCmd = true
```

To tell Cobra *not* to provide the user with the `--no-descriptions` flag to the completion sub-commands:
To tell Cobra *not* to provide the user with the `--no-descriptions` flag or the same functionality using `*_COMPLETION_DESCRIPTIONS` environment variables to the completion sub-commands:
```
rootCmd.CompletionOptions.DisableNoDescFlag = true
```
Expand Down Expand Up @@ -393,6 +393,9 @@ $ source <(helm completion bash --no-descriptions)
$ helm completion [tab][tab]
bash fish powershell zsh
```

Setting the `<PROGRAM>_COMPLETION_DESCRIPTIONS` environment variable (falling back to `COBRA_COMPLETION_DESCRIPTIONS` if empty or not set) to `off` achieves the same. `<PROGRAM>` is the name of your program with all non-ASCII-alphanumeric characters replaced by `_`.

## Bash completions

### Dependencies
Expand Down

0 comments on commit 4474cf6

Please sign in to comment.