瀏覽代碼

Merge pull request #6839 from xiang90/ctl_v

etcdctl: etcdctl v3 should print out its API version
Xiang Li 9 年之前
父節點
當前提交
4d5a12a248
共有 3 個文件被更改,包括 19 次插入9 次删除
  1. 1 9
      etcdctl/ctlv3/command/version_command.go
  2. 8 0
      etcdctl/ctlv3/help.go
  3. 10 0
      version/version.go

+ 1 - 9
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)
 }

+ 8 - 0
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

+ 10 - 0
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"`