etcdctl: etcdctl v3 should print out its API version

release-3.1
Xiang Li 2016-11-11 09:26:02 -08:00
parent 952eb4fade
commit 1ef243e436
3 changed files with 19 additions and 9 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -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"`