rmdir_command.go 754 B

1234567891011121314151617181920212223242526272829
  1. package command
  2. import (
  3. "errors"
  4. "github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
  5. "github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd"
  6. )
  7. // NewRemoveCommand returns the CLI command for "rmdir".
  8. func NewRemoveDirCommand() cli.Command {
  9. return cli.Command{
  10. Name: "rmdir",
  11. Usage: "removes the key if it is an empty directory or a key-value pair",
  12. Action: func(c *cli.Context) {
  13. handleDir(c, removeDirCommandFunc)
  14. },
  15. }
  16. }
  17. // removeDirCommandFunc executes the "rmdir" command.
  18. func removeDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
  19. if len(c.Args()) == 0 {
  20. return nil, errors.New("Key required")
  21. }
  22. key := c.Args()[0]
  23. return client.DeleteDir(key)
  24. }