commands: move catalog command to separate pkg

This commit is contained in:
Frank Schroeder 2017-10-11 16:43:46 +02:00 committed by Frank Schröder
parent 5d75449419
commit bcf53b98d1
4 changed files with 30 additions and 50 deletions

View File

@ -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 <subcommand> [options] [args]
func (c *cmd) Synopsis() string {
return "Interact with the catalog"
}
func (c *cmd) Help() string {
s := `Usage: consul catalog <subcommand> [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 <subcommand> [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)
}

View File

@ -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")
}
}

View File

@ -1,8 +0,0 @@
package command
import "testing"
func TestCatalogCommand_noTabs(t *testing.T) {
t.Parallel()
assertNoTabs(t, new(CatalogCommand))
}

View File

@ -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)
}