commands: move operator raft command to separate pkg

This commit is contained in:
Frank Schroeder 2017-10-17 08:03:03 +02:00 committed by Frank Schröder
parent cc103391b2
commit f10f07b448
4 changed files with 28 additions and 42 deletions

View File

@ -28,6 +28,7 @@ import (
"github.com/hashicorp/consul/command/members" "github.com/hashicorp/consul/command/members"
"github.com/hashicorp/consul/command/monitor" "github.com/hashicorp/consul/command/monitor"
"github.com/hashicorp/consul/command/oper" "github.com/hashicorp/consul/command/oper"
"github.com/hashicorp/consul/command/operraft"
"github.com/hashicorp/consul/command/validate" "github.com/hashicorp/consul/command/validate"
"github.com/hashicorp/consul/version" "github.com/hashicorp/consul/version"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
@ -174,12 +175,7 @@ func init() {
}, },
"operator raft": func() (cli.Command, error) { "operator raft": func() (cli.Command, error) {
return &OperatorRaftCommand{ return operraft.New(), nil
BaseCommand: BaseCommand{
Flags: FlagSetHTTP,
UI: ui,
},
}, nil
}, },
"operator raft list-peers": func() (cli.Command, error) { "operator raft list-peers": func() (cli.Command, error) {

View File

@ -1,22 +0,0 @@
package command
import (
"testing"
"github.com/mitchellh/cli"
)
func testOperatorRaftCommand(t *testing.T) (*cli.MockUi, *OperatorRaftCommand) {
ui := cli.NewMockUi()
return ui, &OperatorRaftCommand{
BaseCommand: BaseCommand{
UI: ui,
Flags: FlagSetHTTP,
},
}
}
func TestOperator_Raft_Implements(t *testing.T) {
t.Parallel()
var _ cli.Command = &OperatorRaftCommand{}
}

View File

@ -1,21 +1,25 @@
package command package operraft
import ( import (
"strings"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
) )
type OperatorRaftCommand struct { func New() *cmd {
BaseCommand return &cmd{}
} }
func (c *OperatorRaftCommand) Run(args []string) int { type cmd struct{}
func (c *cmd) Run(args []string) int {
return cli.RunResultHelp return cli.RunResultHelp
} }
func (c *OperatorRaftCommand) Help() string { func (c *cmd) Synopsis() string {
helpText := ` return "Provides cluster-level tools for Consul operators"
}
func (c *cmd) Help() string {
s := `
Usage: consul operator raft <subcommand> [options] Usage: consul operator raft <subcommand> [options]
The Raft operator command is used to interact with Consul's Raft subsystem. The The Raft operator command is used to interact with Consul's Raft subsystem. The
@ -23,10 +27,5 @@ command can be used to verify Raft peers or in rare cases to recover quorum by
removing invalid peers. removing invalid peers.
` `
return s
return strings.TrimSpace(helpText)
}
func (c *OperatorRaftCommand) Synopsis() string {
return "Provides cluster-level tools for Consul operators"
} }

View File

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