浏览代码

ctlv3: handle pkg/flags warnings

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
Gyuho Lee 8 年之前
父节点
当前提交
8a66237693
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      etcdctl/ctlv3/command/global.go

+ 11 - 0
etcdctl/ctlv3/command/global.go

@@ -101,8 +101,19 @@ type clientConfig struct {
 	acfg             *authCfg
 	acfg             *authCfg
 }
 }
 
 
+type discardValue struct{}
+
+func (*discardValue) String() string   { return "" }
+func (*discardValue) Set(string) error { return nil }
+func (*discardValue) Type() string     { return "" }
+
 func clientConfigFromCmd(cmd *cobra.Command) *clientConfig {
 func clientConfigFromCmd(cmd *cobra.Command) *clientConfig {
 	fs := cmd.InheritedFlags()
 	fs := cmd.InheritedFlags()
+
+	// silence "pkg/flags: unrecognized environment variable ETCDCTL_WATCH_KEY=foo" warnings
+	// silence "pkg/flags: unrecognized environment variable ETCDCTL_WATCH_RANGE_END=bar" warnings
+	fs.AddFlag(&pflag.Flag{Name: "watch-key", Value: &discardValue{}})
+	fs.AddFlag(&pflag.Flag{Name: "watch-range-end", Value: &discardValue{}})
 	flags.SetPflagsFromEnv("ETCDCTL", fs)
 	flags.SetPflagsFromEnv("ETCDCTL", fs)
 
 
 	debug, err := cmd.Flags().GetBool("debug")
 	debug, err := cmd.Flags().GetBool("debug")