etcdctl/ctlv3: etcd v3.4 makes ETCDCTL_API=3 by default

This commit is contained in:
Vimal K
2018-05-29 02:44:45 +05:30
parent 476c9cbeed
commit 25bc65794f
8 changed files with 50 additions and 18 deletions

View File

@@ -26,7 +26,7 @@ import (
"github.com/urfave/cli"
)
func Start(apiv string) {
func Start() {
app := cli.NewApp()
app.Name = "etcdctl"
app.Version = version.Version
@@ -36,13 +36,6 @@ func Start(apiv string) {
}
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"},

View File

@@ -23,9 +23,16 @@ import (
"github.com/coreos/etcd/etcdctl/ctlv3/command"
)
func Start() {
func Start(apiv string) {
// ETCDCTL_ARGS=etcdctl_test arg1 arg2...
// SetArgs() takes arg1 arg2...
if apiv == "" {
rootCmd.Short += "\n\n" +
"WARNING:\n" +
" Environment variable ETCDCTL_API is not set; defaults to etcdctl v3.\n" +
" Set environment variable ETCDCTL_API=2 to use v2 API or ETCDCTL_API=3 to use v3 API."
}
rootCmd.SetArgs(strings.Split(os.Getenv("ETCDCTL_ARGS"), "\xe7\xcd")[1:])
os.Unsetenv("ETCDCTL_ARGS")
if err := rootCmd.Execute(); err != nil {

View File

@@ -18,7 +18,14 @@ package ctlv3
import "github.com/coreos/etcd/etcdctl/ctlv3/command"
func Start() {
func Start(apiv string) {
if apiv == "" {
rootCmd.Short += "\n\n" +
"WARNING:\n" +
" Environment variable ETCDCTL_API is not set; defaults to etcdctl v3.\n" +
" Set environment variable ETCDCTL_API=2 to use v2 API or ETCDCTL_API=3 to use v3 API."
}
rootCmd.SetUsageFunc(usageFunc)
// Make help just show the usage
rootCmd.SetHelpTemplate(`{{.UsageString}}`)

View File

@@ -31,13 +31,13 @@ func main() {
apiv := os.Getenv(apiEnv)
// unset apiEnv to avoid side-effect for future env and flag parsing.
os.Unsetenv(apiEnv)
if len(apiv) == 0 || apiv == "2" {
ctlv2.Start(apiv)
if len(apiv) == 0 || apiv == "3" {
ctlv3.Start(apiv)
return
}
if apiv == "3" {
ctlv3.Start()
if apiv == "2" {
ctlv2.Start()
return
}