Browse Source

ctlv3: add '--ignore-lease' flag to put command

sharat 9 years ago
parent
commit
84a81d8caf
2 changed files with 24 additions and 3 deletions
  1. 12 0
      etcdctl/README.md
  2. 12 3
      etcdctl/ctlv3/command/put_command.go

+ 12 - 0
etcdctl/README.md

@@ -31,6 +31,8 @@ RPC: Put
 
 
 - ignore-value -- updates the key using its current value.
 - ignore-value -- updates the key using its current value.
 
 
+- ignore-lease -- updates the key using its current lease.
+
 #### Output
 #### Output
 
 
 `OK`
 `OK`
@@ -47,6 +49,16 @@ RPC: Put
 # OK
 # 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
 ```bash
 ./etcdctl put foo bar1 --prev-kv
 ./etcdctl put foo bar1 --prev-kv
 # OK
 # OK

+ 12 - 3
etcdctl/ctlv3/command/put_command.go

@@ -24,9 +24,10 @@ import (
 )
 )
 
 
 var (
 var (
-	leaseStr     string
-	putPrevKV    bool
-	putIgnoreVal bool
+	leaseStr       string
+	putPrevKV      bool
+	putIgnoreVal   bool
+	putIgnoreLease bool
 )
 )
 
 
 // NewPutCommand returns the cobra command for "put".
 // NewPutCommand returns the cobra command for "put".
@@ -46,6 +47,9 @@ $ put -- <key> <value>
 If <value> isn't given as a command line argument and '--ignore-value' is not specified,
 If <value> isn't given as a command line argument and '--ignore-value' is not specified,
 this command tries to read the value from standard input.
 this command tries to read the value from standard input.
 
 
+If <lease> 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,
 For example,
 $ cat file | put <key>
 $ cat file | put <key>
 will store the content of the file to <key>.
 will store the content of the file to <key>.
@@ -55,6 +59,7 @@ will store the content of the file to <key>.
 	cmd.Flags().StringVar(&leaseStr, "lease", "0", "lease ID (in hexadecimal) to attach to the key")
 	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(&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(&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
 	return cmd
 }
 }
 
 
@@ -80,6 +85,7 @@ func getPutOp(cmd *cobra.Command, args []string) (string, string, []clientv3.OpO
 	if putIgnoreVal && len(args) > 1 {
 	if putIgnoreVal && len(args) > 1 {
 		ExitWithError(ExitBadArgs, fmt.Errorf("put command needs only 1 argument when 'ignore-value' is set."))
 		ExitWithError(ExitBadArgs, fmt.Errorf("put command needs only 1 argument when 'ignore-value' is set."))
 	}
 	}
+
 	var value string
 	var value string
 	var err error
 	var err error
 	if !putIgnoreVal {
 	if !putIgnoreVal {
@@ -104,6 +110,9 @@ func getPutOp(cmd *cobra.Command, args []string) (string, string, []clientv3.OpO
 	if putIgnoreVal {
 	if putIgnoreVal {
 		opts = append(opts, clientv3.WithIgnoreValue())
 		opts = append(opts, clientv3.WithIgnoreValue())
 	}
 	}
+	if putIgnoreLease {
+		opts = append(opts, clientv3.WithIgnoreLease())
+	}
 
 
 	return key, value, opts
 	return key, value, opts
 }
 }