From 34319bc78797d2bd39318e2e9b29cbe4e99734fa Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Wed, 9 Aug 2017 14:18:30 -0700 Subject: [PATCH] etcdctl/ctlv3: exit with error on shadowed environment variable flags Signed-off-by: Gyu-Ho Lee --- etcdctl/ctlv3/command/ep_command.go | 4 +++- etcdctl/ctlv3/command/global.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/etcdctl/ctlv3/command/ep_command.go b/etcdctl/ctlv3/command/ep_command.go index 4fac7e44d953..b919b7b6ec2f 100644 --- a/etcdctl/ctlv3/command/ep_command.go +++ b/etcdctl/ctlv3/command/ep_command.go @@ -78,7 +78,9 @@ func newEpHashKVCommand() *cobra.Command { // epHealthCommandFunc executes the "endpoint-health" command. func epHealthCommandFunc(cmd *cobra.Command, args []string) { - flags.SetPflagsFromEnv("ETCDCTL", cmd.InheritedFlags()) + if err := flags.SetPflagsFromEnv("ETCDCTL", cmd.InheritedFlags(), flags.WithNoConflict()); err != nil { + ExitWithError(ExitBadArgs, err) + } sec := secureCfgFromCmd(cmd) dt := dialTimeoutFromCmd(cmd) diff --git a/etcdctl/ctlv3/command/global.go b/etcdctl/ctlv3/command/global.go index 616d32e21ef7..7baf684a7f84 100644 --- a/etcdctl/ctlv3/command/global.go +++ b/etcdctl/ctlv3/command/global.go @@ -81,7 +81,9 @@ func initDisplayFromCmd(cmd *cobra.Command) { } func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client { - flags.SetPflagsFromEnv("ETCDCTL", cmd.InheritedFlags()) + if err := flags.SetPflagsFromEnv("ETCDCTL", cmd.InheritedFlags(), flags.WithNoConflict()); err != nil { + ExitWithError(ExitBadArgs, err) + } debug, derr := cmd.Flags().GetBool("debug") if derr != nil {