commands: move version command to separate pkg
This commit is contained in:
parent
776cffa33d
commit
758199813b
|
@ -39,6 +39,7 @@ import (
|
|||
"github.com/hashicorp/consul/command/snapshot"
|
||||
"github.com/hashicorp/consul/command/snapshotinspect"
|
||||
"github.com/hashicorp/consul/command/validate"
|
||||
versioncmd "github.com/hashicorp/consul/command/version"
|
||||
"github.com/hashicorp/consul/version"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
@ -219,10 +220,7 @@ func init() {
|
|||
},
|
||||
|
||||
"version": func() (cli.Command, error) {
|
||||
return &VersionCommand{
|
||||
HumanVersion: version.GetHumanVersion(),
|
||||
UI: ui,
|
||||
}, nil
|
||||
return versioncmd.New(ui, version.GetHumanVersion()), nil
|
||||
},
|
||||
|
||||
"watch": func() (cli.Command, error) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package command
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -8,18 +8,25 @@ import (
|
|||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
// VersionCommand is a Command implementation prints the version.
|
||||
type VersionCommand struct {
|
||||
HumanVersion string
|
||||
UI cli.Ui
|
||||
func New(ui cli.Ui, version string) *cmd {
|
||||
return &cmd{UI: ui, version: version}
|
||||
}
|
||||
|
||||
func (c *VersionCommand) Help() string {
|
||||
type cmd struct {
|
||||
UI cli.Ui
|
||||
version string
|
||||
}
|
||||
|
||||
func (c *cmd) Synopsis() string {
|
||||
return "Prints the Consul version"
|
||||
}
|
||||
|
||||
func (c *cmd) Help() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *VersionCommand) Run(_ []string) int {
|
||||
c.UI.Output(fmt.Sprintf("Consul %s", c.HumanVersion))
|
||||
func (c *cmd) Run(_ []string) int {
|
||||
c.UI.Output(fmt.Sprintf("Consul %s", c.version))
|
||||
|
||||
rpcProtocol, err := config.DefaultRPCProtocol()
|
||||
if err != nil {
|
||||
|
@ -36,7 +43,3 @@ func (c *VersionCommand) Run(_ []string) int {
|
|||
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *VersionCommand) Synopsis() string {
|
||||
return "Prints the Consul version"
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
func TestVersionCommand_noTabs(t *testing.T) {
|
||||
t.Parallel()
|
||||
if strings.ContainsRune(New(cli.NewMockUi(), "").Help(), '\t') {
|
||||
t.Fatal("usage has tabs")
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
func TestVersionCommand_implements(t *testing.T) {
|
||||
t.Parallel()
|
||||
var _ cli.Command = &VersionCommand{}
|
||||
}
|
Loading…
Reference in New Issue