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" "fmt"
"github.com/coreos/etcd/version" "github.com/coreos/etcd/version"
"github.com/coreos/go-semver/semver"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -33,12 +32,5 @@ func NewVersionCommand() *cobra.Command {
func versionCommandFunc(cmd *cobra.Command, args []string) { func versionCommandFunc(cmd *cobra.Command, args []string) {
fmt.Println("etcdctl version:", version.Version) fmt.Println("etcdctl version:", version.Version)
ver, err := semver.NewVersion(version.Version) fmt.Println("API version:", version.APIVersion)
var vs string
if err == nil {
vs = fmt.Sprintf("%d.%d", ver.Major, ver.Minor)
} else {
vs = "unknown"
}
fmt.Println("API version:", vs)
} }

View File

@ -68,6 +68,12 @@ VERSION:
{{end}}\ {{end}}\
{{if .Cmd.HasSubCommands}}\ {{if .Cmd.HasSubCommands}}\
API VERSION:
{{printf "\t%s" .APIVersion}}
{{end}}\
{{if .Cmd.HasSubCommands}}\
COMMANDS: COMMANDS:
{{range .SubCommands}}\ {{range .SubCommands}}\
{{ $cmdname := cmdName . $cmd }}\ {{ $cmdname := cmdName . $cmd }}\
@ -148,12 +154,14 @@ func usageFunc(cmd *cobra.Command) error {
GlobalFlags string GlobalFlags string
SubCommands []*cobra.Command SubCommands []*cobra.Command
Version string Version string
APIVersion string
}{ }{
cmd, cmd,
etcdFlagUsages(cmd.LocalFlags()), etcdFlagUsages(cmd.LocalFlags()),
etcdFlagUsages(cmd.InheritedFlags()), etcdFlagUsages(cmd.InheritedFlags()),
subCommands, subCommands,
version.Version, version.Version,
version.APIVersion,
}) })
tabOut.Flush() tabOut.Flush()
return nil return nil

View File

@ -19,17 +19,27 @@ package version
import ( import (
"fmt" "fmt"
"strings" "strings"
"github.com/coreos/go-semver/semver"
) )
var ( var (
// MinClusterVersion is the min cluster version this etcd binary is compatible with. // MinClusterVersion is the min cluster version this etcd binary is compatible with.
MinClusterVersion = "3.0.0" MinClusterVersion = "3.0.0"
Version = "3.1.0-rc.0+git" Version = "3.1.0-rc.0+git"
APIVersion = "unknown"
// Git SHA Value will be set during build // Git SHA Value will be set during build
GitSHA = "Not provided (use ./build instead of go 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 { type Versions struct {
Server string `json:"etcdserver"` Server string `json:"etcdserver"`
Cluster string `json:"etcdcluster"` Cluster string `json:"etcdcluster"`