浏览代码

etcdctl: rmdir use etcd/client

Xiang Li 10 年之前
父节点
当前提交
58b19a7c1e
共有 1 个文件被更改,包括 15 次插入6 次删除
  1. 15 6
      etcdctl/command/rmdir_command.go

+ 15 - 6
etcdctl/command/rmdir_command.go

@@ -18,7 +18,8 @@ import (
 	"errors"
 	"errors"
 
 
 	"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
 	"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
-	"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd"
+	"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
+	"github.com/coreos/etcd/client"
 )
 )
 
 
 // NewRemoveCommand returns the CLI command for "rmdir".
 // NewRemoveCommand returns the CLI command for "rmdir".
@@ -27,17 +28,25 @@ func NewRemoveDirCommand() cli.Command {
 		Name:  "rmdir",
 		Name:  "rmdir",
 		Usage: "removes the key if it is an empty directory or a key-value pair",
 		Usage: "removes the key if it is an empty directory or a key-value pair",
 		Action: func(c *cli.Context) {
 		Action: func(c *cli.Context) {
-			handleDir(c, removeDirCommandFunc)
+			rmdirCommandFunc(c, mustNewKeyAPI(c))
 		},
 		},
 	}
 	}
 }
 }
 
 
-// removeDirCommandFunc executes the "rmdir" command.
-func removeDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
+// rmdirCommandFunc executes the "rmdir" command.
+func rmdirCommandFunc(c *cli.Context, ki client.KeysAPI) {
 	if len(c.Args()) == 0 {
 	if len(c.Args()) == 0 {
-		return nil, errors.New("key required")
+		handleError(ExitBadArgs, errors.New("key required"))
 	}
 	}
 	key := c.Args()[0]
 	key := c.Args()[0]
 
 
-	return client.DeleteDir(key)
+	// TODO: handle transport timeout
+	resp, err := ki.Delete(context.TODO(), key, &client.DeleteOptions{Dir: true})
+	if err != nil {
+		handleError(ExitServerError, err)
+	}
+
+	if !resp.Node.Dir {
+		printResponseKey(resp, c.GlobalString("output"))
+	}
 }
 }