main: Hide several commands from our help

These are commands that either no longer do anything aside from emitting
an error message or are just backward-compatibility aliases for other
commands.

This generalizes our previous situation where we were specifically
hiding "internal-plugin", and does so in a way that fixes the
long-standing cosmetic bug that the column width in the help output was
chosen based on the hidden command "internal-plugin", which is
unfortunately also the longest command in our command set.
This commit is contained in:
Martin Atkins 2020-10-23 15:48:46 -07:00
parent 39504ede05
commit f44265e59e
2 changed files with 15 additions and 8 deletions

View File

@ -26,6 +26,7 @@ const runningInAutomationEnvName = "TF_IN_AUTOMATION"
// Commands is the mapping of all the available Terraform commands. // Commands is the mapping of all the available Terraform commands.
var Commands map[string]cli.CommandFactory var Commands map[string]cli.CommandFactory
var PlumbingCommands map[string]struct{} var PlumbingCommands map[string]struct{}
var HiddenCommands map[string]struct{}
// Ui is the cli.Ui used for communicating to the outside world. // Ui is the cli.Ui used for communicating to the outside world.
var Ui cli.Ui var Ui cli.Ui
@ -96,9 +97,14 @@ func initCommands(
PlumbingCommands = map[string]struct{}{ PlumbingCommands = map[string]struct{}{
"state": struct{}{}, // includes all subcommands "state": struct{}{}, // includes all subcommands
"force-unlock": struct{}{}, "force-unlock": struct{}{},
"push": struct{}{}, }
"0.12upgrade": struct{}{},
"0.13upgrade": struct{}{}, HiddenCommands = map[string]struct{}{
"0.12upgrade": struct{}{},
"0.13upgrade": struct{}{},
"env": struct{}{},
"internal-plugin": struct{}{},
"push": struct{}{},
} }
Commands = map[string]cli.CommandFactory{ Commands = map[string]cli.CommandFactory{

11
help.go
View File

@ -17,6 +17,12 @@ func helpFunc(commands map[string]cli.CommandFactory) string {
plumbing := make(map[string]cli.CommandFactory) plumbing := make(map[string]cli.CommandFactory)
maxKeyLen := 0 maxKeyLen := 0
for key, f := range commands { for key, f := range commands {
if _, ok := HiddenCommands[key]; ok {
// We don't consider hidden commands when deciding the
// maximum command length.
continue
}
if len(key) > maxKeyLen { if len(key) > maxKeyLen {
maxKeyLen = len(key) maxKeyLen = len(key)
} }
@ -65,11 +71,6 @@ func listCommands(commands map[string]cli.CommandFactory, maxKeyLen int) string
// key length so they can be aligned properly. // key length so they can be aligned properly.
keys := make([]string, 0, len(commands)) keys := make([]string, 0, len(commands))
for key, _ := range commands { for key, _ := range commands {
// This is an internal command that users should never call directly so
// we will hide it from the command listing.
if key == "internal-plugin" {
continue
}
keys = append(keys, key) keys = append(keys, key)
} }
sort.Strings(keys) sort.Strings(keys)