commands: move operator command to separate pkg

This commit is contained in:
Frank Schroeder 2017-10-17 07:58:03 +02:00 committed by Frank Schröder
parent 684362b1d0
commit fe84af448b
4 changed files with 31 additions and 38 deletions

View File

@ -27,6 +27,7 @@ import (
"github.com/hashicorp/consul/command/maint"
"github.com/hashicorp/consul/command/members"
"github.com/hashicorp/consul/command/monitor"
"github.com/hashicorp/consul/command/oper"
"github.com/hashicorp/consul/command/validate"
"github.com/hashicorp/consul/version"
"github.com/mitchellh/cli"
@ -142,12 +143,7 @@ func init() {
},
"operator": func() (cli.Command, error) {
return &OperatorCommand{
BaseCommand: BaseCommand{
Flags: FlagSetNone,
UI: ui,
},
}, nil
return oper.New(), nil
},
"operator autopilot": func() (cli.Command, error) {

View File

@ -1,20 +1,25 @@
package command
package oper
import (
"strings"
"github.com/mitchellh/cli"
)
// OperatorCommand is used to provide various low-level tools for Consul
// operators.
type OperatorCommand struct {
BaseCommand
func New() *cmd {
return &cmd{}
}
func (c *OperatorCommand) Help() string {
helpText := `
Usage: consul operator <subcommand> [options]
type cmd struct{}
func (c *cmd) Run(args []string) int {
return cli.RunResultHelp
}
func (c *cmd) Synopsis() string {
return "Provides cluster-level tools for Consul operators"
}
func (c *cmd) Help() string {
s := `Usage: consul operator <subcommand> [options]
Provides cluster-level tools for Consul operators, such as interacting with
the Raft subsystem. NOTE: Use this command with extreme caution, as improper
@ -27,14 +32,5 @@ Usage: consul operator <subcommand> [options]
Run consul operator <subcommand> with no arguments for help on that
subcommand.
`
return strings.TrimSpace(helpText)
}
func (c *OperatorCommand) Run(args []string) int {
return cli.RunResultHelp
}
// Synopsis returns a one-line description of this command.
func (c *OperatorCommand) Synopsis() string {
return "Provides cluster-level tools for Consul operators"
return s
}

View File

@ -0,0 +1,13 @@
package oper
import (
"strings"
"testing"
)
func TestOperatorCommand_noTabs(t *testing.T) {
t.Parallel()
if strings.ContainsRune(New().Help(), '\t') {
t.Fatal("usage has tabs")
}
}

View File

@ -1,12 +0,0 @@
package command
import (
"testing"
"github.com/mitchellh/cli"
)
func TestOperator_Implements(t *testing.T) {
t.Parallel()
var _ cli.Command = &OperatorCommand{}
}