From 1e38ab1706ce08afb65962f0a1bad3a02d18ca0f Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Tue, 14 Jun 2016 15:25:18 -0700 Subject: [PATCH] etcdctl: print API version (v2, v3 separate) --- etcdctl/ctlv2/ctl.go | 5 +++++ etcdctl/ctlv3/command/version_command.go | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/etcdctl/ctlv2/ctl.go b/etcdctl/ctlv2/ctl.go index 5a65fac3e..8018d40a2 100644 --- a/etcdctl/ctlv2/ctl.go +++ b/etcdctl/ctlv2/ctl.go @@ -16,6 +16,7 @@ package ctlv2 import ( + "fmt" "os" "time" @@ -28,6 +29,10 @@ func Start() { app := cli.NewApp() app.Name = "etcdctl" app.Version = version.Version + cli.VersionPrinter = func(c *cli.Context) { + fmt.Fprintf(c.App.Writer, "etcdctl version: %v\n", c.App.Version) + fmt.Fprintln(c.App.Writer, "API version: 2") + } app.Usage = "A simple command line client for etcd." app.Flags = []cli.Flag{ cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"}, diff --git a/etcdctl/ctlv3/command/version_command.go b/etcdctl/ctlv3/command/version_command.go index d233c8cdd..c43cbd46e 100644 --- a/etcdctl/ctlv3/command/version_command.go +++ b/etcdctl/ctlv3/command/version_command.go @@ -18,6 +18,7 @@ import ( "fmt" "github.com/coreos/etcd/version" + "github.com/coreos/go-semver/semver" "github.com/spf13/cobra" ) @@ -31,5 +32,13 @@ func NewVersionCommand() *cobra.Command { } func versionCommandFunc(cmd *cobra.Command, args []string) { - fmt.Println(version.Version) + 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) }