From 1ef243e436e946c193833cc86d53f2ac098a9a0d Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Fri, 11 Nov 2016 09:26:02 -0800 Subject: [PATCH] etcdctl: etcdctl v3 should print out its API version --- etcdctl/ctlv3/command/version_command.go | 10 +--------- etcdctl/ctlv3/help.go | 8 ++++++++ version/version.go | 10 ++++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/etcdctl/ctlv3/command/version_command.go b/etcdctl/ctlv3/command/version_command.go index df68a46b6..9fa990f1f 100644 --- a/etcdctl/ctlv3/command/version_command.go +++ b/etcdctl/ctlv3/command/version_command.go @@ -18,7 +18,6 @@ import ( "fmt" "github.com/coreos/etcd/version" - "github.com/coreos/go-semver/semver" "github.com/spf13/cobra" ) @@ -33,12 +32,5 @@ func NewVersionCommand() *cobra.Command { func versionCommandFunc(cmd *cobra.Command, args []string) { fmt.Println("etcdctl version:", version.Version) - ver, err := semver.NewVersion(version.Version) - var vs string - if err == nil { - vs = fmt.Sprintf("%d.%d", ver.Major, ver.Minor) - } else { - vs = "unknown" - } - fmt.Println("API version:", vs) + fmt.Println("API version:", version.APIVersion) } diff --git a/etcdctl/ctlv3/help.go b/etcdctl/ctlv3/help.go index defe136ed..7051fcd69 100644 --- a/etcdctl/ctlv3/help.go +++ b/etcdctl/ctlv3/help.go @@ -68,6 +68,12 @@ VERSION: {{end}}\ {{if .Cmd.HasSubCommands}}\ +API VERSION: +{{printf "\t%s" .APIVersion}} +{{end}}\ +{{if .Cmd.HasSubCommands}}\ + + COMMANDS: {{range .SubCommands}}\ {{ $cmdname := cmdName . $cmd }}\ @@ -148,12 +154,14 @@ func usageFunc(cmd *cobra.Command) error { GlobalFlags string SubCommands []*cobra.Command Version string + APIVersion string }{ cmd, etcdFlagUsages(cmd.LocalFlags()), etcdFlagUsages(cmd.InheritedFlags()), subCommands, version.Version, + version.APIVersion, }) tabOut.Flush() return nil diff --git a/version/version.go b/version/version.go index 19009263f..2f899a5a9 100644 --- a/version/version.go +++ b/version/version.go @@ -19,17 +19,27 @@ package version import ( "fmt" "strings" + + "github.com/coreos/go-semver/semver" ) var ( // MinClusterVersion is the min cluster version this etcd binary is compatible with. MinClusterVersion = "3.0.0" Version = "3.1.0-rc.0+git" + APIVersion = "unknown" // Git SHA Value will be set during build GitSHA = "Not provided (use ./build instead of go build)" ) +func init() { + ver, err := semver.NewVersion(Version) + if err == nil { + APIVersion = fmt.Sprintf("%d.%d", ver.Major, ver.Minor) + } +} + type Versions struct { Server string `json:"etcdserver"` Cluster string `json:"etcdcluster"`