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

release-3.2
sharat 2017-01-25 03:11:19 +05:30
parent d3191d1afb
commit 84a81d8caf
2 changed files with 24 additions and 3 deletions

View File

@ -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

View File

@ -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 -- <key> <value>
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.
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,
$ cat file | put <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().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
}