Skip to content

Commit

Permalink
cmd/completion: Only suggest whitelisted and visible command for help
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryMichal committed May 20, 2022
1 parent 615bb66 commit 3c0e092
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"os"
"strings"

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

func completionCommands(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
commandNames := []string{}
// init-container is hidden but documented command that is meant to be
// accessed by users at least via a manual page
commandNames := []string{"init-container"}
commands := cmd.Root().Commands()

for _, command := range commands {
if strings.Contains(command.Name(), "complet") {
continue
if !command.Hidden {
commandNames = append(commandNames, command.Name())
}
commandNames = append(commandNames, command.Name())
}

return commandNames, cobra.ShellCompDirectiveNoFileComp
Expand Down

0 comments on commit 3c0e092

Please sign in to comment.