From f76ca01aed507aedd50c1c26f458913a2e2dfb41 Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Tue, 28 Feb 2017 16:21:03 -0800 Subject: [PATCH] etcdctl: show warning if ETCDCTL_API is not set in v2 --help FIXES #7385 --- etcdctl/ctlv2/ctl.go | 10 +++++++++- etcdctl/main.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/etcdctl/ctlv2/ctl.go b/etcdctl/ctlv2/ctl.go index 800ac85e4..e949b06f0 100644 --- a/etcdctl/ctlv2/ctl.go +++ b/etcdctl/ctlv2/ctl.go @@ -25,7 +25,7 @@ import ( "github.com/urfave/cli" ) -func Start() { +func Start(apiv string) { app := cli.NewApp() app.Name = "etcdctl" app.Version = version.Version @@ -34,6 +34,14 @@ func Start() { fmt.Fprintln(c.App.Writer, "API version: 2") } app.Usage = "A simple command line client for etcd." + + if apiv == "" { + app.Usage += "\n\n" + + "WARNING:\n" + + " Environment variable ETCDCTL_API is not set; defaults to etcdctl v2.\n" + + " Set environment variable ETCDCTL_API=3 to use v3 API or ETCDCTL_API=2 to use v2 API." + } + app.Flags = []cli.Flag{ cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"}, cli.BoolFlag{Name: "no-sync", Usage: "don't synchronize cluster information before sending request"}, diff --git a/etcdctl/main.go b/etcdctl/main.go index 85cdff5cc..b5c7bddb0 100644 --- a/etcdctl/main.go +++ b/etcdctl/main.go @@ -32,7 +32,7 @@ func main() { // unset apiEnv to avoid side-effect for future env and flag parsing. os.Unsetenv(apiEnv) if len(apiv) == 0 || apiv == "2" { - ctlv2.Start() + ctlv2.Start(apiv) return }