|
@@ -22,8 +22,9 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
var (
|
|
|
- delPrefix bool
|
|
|
|
|
- delPrevKV bool
|
|
|
|
|
|
|
+ delPrefix bool
|
|
|
|
|
+ delPrevKV bool
|
|
|
|
|
+ delFromKey bool
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// NewDelCommand returns the cobra command for "del".
|
|
// NewDelCommand returns the cobra command for "del".
|
|
@@ -36,7 +37,7 @@ func NewDelCommand() *cobra.Command {
|
|
|
|
|
|
|
|
cmd.Flags().BoolVar(&delPrefix, "prefix", false, "delete keys with matching prefix")
|
|
cmd.Flags().BoolVar(&delPrefix, "prefix", false, "delete keys with matching prefix")
|
|
|
cmd.Flags().BoolVar(&delPrevKV, "prev-kv", false, "return deleted key-value pairs")
|
|
cmd.Flags().BoolVar(&delPrevKV, "prev-kv", false, "return deleted key-value pairs")
|
|
|
-
|
|
|
|
|
|
|
+ cmd.Flags().BoolVar(&delFromKey, "from-key", false, "delete keys that are greater than or equal to the given key using byte compare")
|
|
|
return cmd
|
|
return cmd
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -56,11 +57,16 @@ func getDelOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) {
|
|
|
if len(args) == 0 || len(args) > 2 {
|
|
if len(args) == 0 || len(args) > 2 {
|
|
|
ExitWithError(ExitBadArgs, fmt.Errorf("del command needs one argument as key and an optional argument as range_end."))
|
|
ExitWithError(ExitBadArgs, fmt.Errorf("del command needs one argument as key and an optional argument as range_end."))
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if delPrefix && delFromKey {
|
|
|
|
|
+ ExitWithError(ExitBadArgs, fmt.Errorf("`--prefix` and `--from-key` cannot be set at the same time, choose one."))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
opts := []clientv3.OpOption{}
|
|
opts := []clientv3.OpOption{}
|
|
|
key := args[0]
|
|
key := args[0]
|
|
|
if len(args) > 1 {
|
|
if len(args) > 1 {
|
|
|
- if delPrefix {
|
|
|
|
|
- ExitWithError(ExitBadArgs, fmt.Errorf("too many arguments, only accept one argument when `--prefix` is set."))
|
|
|
|
|
|
|
+ if delPrefix || delFromKey {
|
|
|
|
|
+ ExitWithError(ExitBadArgs, fmt.Errorf("too many arguments, only accept one argument when `--prefix` or `--from-key` is set."))
|
|
|
}
|
|
}
|
|
|
opts = append(opts, clientv3.WithRange(args[1]))
|
|
opts = append(opts, clientv3.WithRange(args[1]))
|
|
|
}
|
|
}
|
|
@@ -72,5 +78,12 @@ func getDelOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) {
|
|
|
opts = append(opts, clientv3.WithPrevKV())
|
|
opts = append(opts, clientv3.WithPrevKV())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if delFromKey {
|
|
|
|
|
+ if len(key) == 0 {
|
|
|
|
|
+ key = "\x00"
|
|
|
|
|
+ }
|
|
|
|
|
+ opts = append(opts, clientv3.WithFromKey())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return key, opts
|
|
return key, opts
|
|
|
}
|
|
}
|