mirror of
https://github.com/status-im/consul.git
synced 2025-02-16 15:47:21 +00:00
commands: move version command to separate pkg
This commit is contained in:
parent
3a02ce9ebc
commit
3acbc278f0
@ -39,6 +39,7 @@ import (
|
|||||||
"github.com/hashicorp/consul/command/snapshot"
|
"github.com/hashicorp/consul/command/snapshot"
|
||||||
"github.com/hashicorp/consul/command/snapshotinspect"
|
"github.com/hashicorp/consul/command/snapshotinspect"
|
||||||
"github.com/hashicorp/consul/command/validate"
|
"github.com/hashicorp/consul/command/validate"
|
||||||
|
versioncmd "github.com/hashicorp/consul/command/version"
|
||||||
"github.com/hashicorp/consul/version"
|
"github.com/hashicorp/consul/version"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
@ -219,10 +220,7 @@ func init() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
"version": func() (cli.Command, error) {
|
"version": func() (cli.Command, error) {
|
||||||
return &VersionCommand{
|
return versioncmd.New(ui, version.GetHumanVersion()), nil
|
||||||
HumanVersion: version.GetHumanVersion(),
|
|
||||||
UI: ui,
|
|
||||||
}, nil
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"watch": func() (cli.Command, error) {
|
"watch": func() (cli.Command, error) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package command
|
package version
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -8,18 +8,25 @@ import (
|
|||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VersionCommand is a Command implementation prints the version.
|
func New(ui cli.Ui, version string) *cmd {
|
||||||
type VersionCommand struct {
|
return &cmd{UI: ui, version: version}
|
||||||
HumanVersion string
|
|
||||||
UI cli.Ui
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *VersionCommand) Run(_ []string) int {
|
func (c *cmd) Run(_ []string) int {
|
||||||
c.UI.Output(fmt.Sprintf("Consul %s", c.HumanVersion))
|
c.UI.Output(fmt.Sprintf("Consul %s", c.version))
|
||||||
|
|
||||||
rpcProtocol, err := config.DefaultRPCProtocol()
|
rpcProtocol, err := config.DefaultRPCProtocol()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -36,7 +43,3 @@ func (c *VersionCommand) Run(_ []string) int {
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *VersionCommand) Synopsis() string {
|
|
||||||
return "Prints the Consul version"
|
|
||||||
}
|
|
15
command/version/version_test.go
Normal file
15
command/version/version_test.go
Normal file
@ -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…
x
Reference in New Issue
Block a user