Avoid redundant active help enablement evaluations

The enablement state is not to be changed during completion output, so
evaluate it only once.
This commit is contained in:
Ville Skyttä 2023-05-10 00:03:16 +03:00
parent 79fb3dd0cf
commit 3f1c31c21e

View file

@ -217,14 +217,13 @@ func (c *Command) initCompleteCmd(args []string) {
}
noDescriptions := (cmd.CalledAs() == ShellCompNoDescRequestCmd)
noActiveHelp := GetActiveHelpConfig(finalCmd) == activeHelpGlobalDisable
out := finalCmd.OutOrStdout()
for _, comp := range completions {
if GetActiveHelpConfig(finalCmd) == activeHelpGlobalDisable {
// Remove all activeHelp entries in this case
if strings.HasPrefix(comp, activeHelpMarker) {
if noActiveHelp && strings.HasPrefix(comp, activeHelpMarker) {
// Remove all activeHelp entries if it's disabled.
continue
}
}
if noDescriptions {
// Remove any description that may be included following a tab character.
comp = strings.SplitN(comp, "\t", 2)[0]