mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #5652 from gyuho/version
etcdctl/*: print API version
This commit is contained in:
commit
a6fec46c0e
@ -16,6 +16,7 @@
|
|||||||
package ctlv2
|
package ctlv2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -28,6 +29,10 @@ func Start() {
|
|||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "etcdctl"
|
app.Name = "etcdctl"
|
||||||
app.Version = version.Version
|
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.Usage = "A simple command line client for etcd."
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"},
|
cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"},
|
||||||
|
@ -18,6 +18,7 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,5 +32,13 @@ func NewVersionCommand() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func versionCommandFunc(cmd *cobra.Command, args []string) {
|
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)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user