Browse Source

Merge pull request #6660 from gyuho/delete-all-keys

etcdctl/ctlv3: support del all keys with '--prefix'
Gyu-Ho Lee 9 years ago
parent
commit
7022d2d00c
2 changed files with 16 additions and 1 deletions
  1. 10 0
      e2e/ctl_v3_kv_test.go
  2. 6 1
      etcdctl/ctlv3/command/del_command.go

+ 10 - 0
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"},

+ 6 - 1
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())