From fac20b228d9aba97aa6605ccf3bc5c0b11aa0073 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Mon, 17 Oct 2016 09:33:59 -0700 Subject: [PATCH 1/2] ctlv3: support del all keys by '--prefix' --- etcdctl/ctlv3/command/del_command.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/etcdctl/ctlv3/command/del_command.go b/etcdctl/ctlv3/command/del_command.go index 111ab0209..bb0663024 100644 --- a/etcdctl/ctlv3/command/del_command.go +++ b/etcdctl/ctlv3/command/del_command.go @@ -72,7 +72,12 @@ func getDelOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) { } if delPrefix { - opts = append(opts, clientv3.WithPrefix()) + if len(key) == 0 { + key = "\x00" + opts = append(opts, clientv3.WithFromKey()) + } else { + opts = append(opts, clientv3.WithPrefix()) + } } if delPrevKV { opts = append(opts, clientv3.WithPrevKV()) From 75a65e1a70ad4cf6bdb2ec7c7fc7ed055535313d Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Mon, 17 Oct 2016 09:34:21 -0700 Subject: [PATCH 2/2] e2e: add test cases for del all keys --- e2e/ctl_v3_kv_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/e2e/ctl_v3_kv_test.go b/e2e/ctl_v3_kv_test.go index 160d877f0..0f1024236 100644 --- a/e2e/ctl_v3_kv_test.go +++ b/e2e/ctl_v3_kv_test.go @@ -180,6 +180,16 @@ func delTest(cx ctlCtx) { deletedNum int }{ + { // delete all keys + []kv{{"foo1", "bar"}, {"foo2", "bar"}, {"foo3", "bar"}}, + []string{"", "--prefix"}, + 3, + }, + { // delete all keys + []kv{{"foo1", "bar"}, {"foo2", "bar"}, {"foo3", "bar"}}, + []string{"", "--from-key"}, + 3, + }, { []kv{{"this", "value"}}, []string{"that"},