Merge pull request #5652 from gyuho/version

etcdctl/*: print API version
This commit is contained in:
Gyu-Ho Lee 2016-06-14 16:04:24 -07:00 committed by GitHub
commit a6fec46c0e
2 changed files with 15 additions and 1 deletions

View File

@ -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"},

View File

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