From 84a81d8caf68c23de012e20fbdce1be094c78203 Mon Sep 17 00:00:00 2001 From: sharat Date: Wed, 25 Jan 2017 03:11:19 +0530 Subject: [PATCH] ctlv3: add '--ignore-lease' flag to put command --- etcdctl/README.md | 12 ++++++++++++ etcdctl/ctlv3/command/put_command.go | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/etcdctl/README.md b/etcdctl/README.md index 4208995c2..a5ff5aa5e 100644 --- a/etcdctl/README.md +++ b/etcdctl/README.md @@ -31,6 +31,8 @@ RPC: Put - ignore-value -- updates the key using its current value. +- ignore-lease -- updates the key using its current lease. + #### Output `OK` @@ -47,6 +49,16 @@ RPC: Put # OK ``` +```bash +./etcdctl put foo bar --lease=1234abcd +# OK +./etcdctl put foo bar1 --ignore-lease # to use existing lease 1234abcd +# OK +./etcdctl get foo +# foo +# bar1 +``` + ```bash ./etcdctl put foo bar1 --prev-kv # OK diff --git a/etcdctl/ctlv3/command/put_command.go b/etcdctl/ctlv3/command/put_command.go index c7d3f07f7..a72f0c4dc 100644 --- a/etcdctl/ctlv3/command/put_command.go +++ b/etcdctl/ctlv3/command/put_command.go @@ -24,9 +24,10 @@ import ( ) var ( - leaseStr string - putPrevKV bool - putIgnoreVal bool + leaseStr string + putPrevKV bool + putIgnoreVal bool + putIgnoreLease bool ) // NewPutCommand returns the cobra command for "put". @@ -46,6 +47,9 @@ $ put -- If isn't given as a command line argument and '--ignore-value' is not specified, this command tries to read the value from standard input. +If isn't given as a command line argument and '--ignore-lease' is not specified, +this command tries to read the value from standard input. + For example, $ cat file | put will store the content of the file to . @@ -55,6 +59,7 @@ will store the content of the file to . cmd.Flags().StringVar(&leaseStr, "lease", "0", "lease ID (in hexadecimal) to attach to the key") cmd.Flags().BoolVar(&putPrevKV, "prev-kv", false, "return the previous key-value pair before modification") cmd.Flags().BoolVar(&putIgnoreVal, "ignore-value", false, "updates the key using its current value") + cmd.Flags().BoolVar(&putIgnoreLease, "ignore-lease", false, "updates the key using its current lease") return cmd } @@ -80,6 +85,7 @@ func getPutOp(cmd *cobra.Command, args []string) (string, string, []clientv3.OpO if putIgnoreVal && len(args) > 1 { ExitWithError(ExitBadArgs, fmt.Errorf("put command needs only 1 argument when 'ignore-value' is set.")) } + var value string var err error if !putIgnoreVal { @@ -104,6 +110,9 @@ func getPutOp(cmd *cobra.Command, args []string) (string, string, []clientv3.OpO if putIgnoreVal { opts = append(opts, clientv3.WithIgnoreValue()) } + if putIgnoreLease { + opts = append(opts, clientv3.WithIgnoreLease()) + } return key, value, opts }