diff --git a/command/catalog_command.go b/command/cat/catalog.go similarity index 65% rename from command/catalog_command.go rename to command/cat/catalog.go index b7edec66c1..e03c72453b 100644 --- a/command/catalog_command.go +++ b/command/cat/catalog.go @@ -1,23 +1,26 @@ -package command +package cat import ( + "github.com/hashicorp/consul/command/flags" "github.com/mitchellh/cli" ) -var _ cli.Command = (*CatalogCommand)(nil) - -type CatalogCommand struct { - BaseCommand +func New() *cmd { + return &cmd{} } -func (c *CatalogCommand) Run(args []string) int { +type cmd struct{} + +func (c *cmd) Run(args []string) int { return cli.RunResultHelp } -func (c *CatalogCommand) Help() string { - c.InitFlagSet() - return c.HelpCommand(` -Usage: consul catalog [options] [args] +func (c *cmd) Synopsis() string { + return "Interact with the catalog" +} + +func (c *cmd) Help() string { + s := `Usage: consul catalog [options] [args] This command has subcommands for interacting with Consul's catalog. The catalog should not be confused with the agent, although the APIs and @@ -38,11 +41,6 @@ Usage: consul catalog [options] [args] $ consul catalog services - For more examples, ask for subcommand help or view the documentation. - -`) -} - -func (c *CatalogCommand) Synopsis() string { - return "Interact with the catalog" + For more examples, ask for subcommand help or view the documentation.` + return flags.Usage(s, nil, nil, nil) } diff --git a/command/cat/catalog_test.go b/command/cat/catalog_test.go new file mode 100644 index 0000000000..2240a85ad0 --- /dev/null +++ b/command/cat/catalog_test.go @@ -0,0 +1,13 @@ +package cat + +import ( + "strings" + "testing" +) + +func TestCatalogCommand_noTabs(t *testing.T) { + t.Parallel() + if strings.ContainsRune(New().Help(), '\t') { + t.Fatal("usage has tabs") + } +} diff --git a/command/catalog_command_test.go b/command/catalog_command_test.go deleted file mode 100644 index 2b6b44a712..0000000000 --- a/command/catalog_command_test.go +++ /dev/null @@ -1,8 +0,0 @@ -package command - -import "testing" - -func TestCatalogCommand_noTabs(t *testing.T) { - t.Parallel() - assertNoTabs(t, new(CatalogCommand)) -} diff --git a/command/commands.go b/command/commands.go index ac416659ca..19773cb087 100644 --- a/command/commands.go +++ b/command/commands.go @@ -1,13 +1,11 @@ package command import ( - "fmt" "os" "os/signal" - "sort" - "strings" "syscall" + "github.com/hashicorp/consul/command/cat" "github.com/hashicorp/consul/command/event" execmd "github.com/hashicorp/consul/command/exec" "github.com/hashicorp/consul/command/forceleave" @@ -49,12 +47,7 @@ func init() { }, "catalog": func() (cli.Command, error) { - return &CatalogCommand{ - BaseCommand: BaseCommand{ - Flags: FlagSetNone, - UI: ui, - }, - }, nil + return cat.New(), nil }, "catalog datacenters": func() (cli.Command, error) { @@ -332,19 +325,3 @@ func makeShutdownCh() <-chan struct{} { return resultCh } - -// mapToKV converts a map[string]string into a human-friendly key=value list, -// sorted by name. -func mapToKV(m map[string]string, joiner string) string { - keys := make([]string, 0, len(m)) - for k := range m { - keys = append(keys, k) - } - sort.Strings(keys) - - r := make([]string, len(keys)) - for i, k := range keys { - r[i] = fmt.Sprintf("%s=%s", k, m[k]) - } - return strings.Join(r, joiner) -}