Skip to content

Commit 3c0e092

Browse files
committed
cmd/completion: Only suggest whitelisted and visible command for help
Fallout from containers#840 containers#1055
1 parent 615bb66 commit 3c0e092

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/cmd/completion.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"fmt"
55
"os"
6-
"strings"
76

87
"github.com/containers/toolbox/pkg/utils"
98
"github.com/spf13/cobra"
@@ -43,13 +42,15 @@ func completionEmpty(_ *cobra.Command, _ []string, _ string) ([]string, cobra.Sh
4342
}
4443

4544
func completionCommands(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
46-
commandNames := []string{}
45+
// init-container is hidden but documented command that is meant to be
46+
// accessed by users at least via a manual page
47+
commandNames := []string{"init-container"}
4748
commands := cmd.Root().Commands()
49+
4850
for _, command := range commands {
49-
if strings.Contains(command.Name(), "complet") {
50-
continue
51+
if !command.Hidden {
52+
commandNames = append(commandNames, command.Name())
5153
}
52-
commandNames = append(commandNames, command.Name())
5354
}
5455

5556
return commandNames, cobra.ShellCompDirectiveNoFileComp

0 commit comments

Comments
 (0)