rmdir_command.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Copyright 2014 CoreOS, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package command
  14. import (
  15. "errors"
  16. "github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
  17. "github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd"
  18. )
  19. // NewRemoveCommand returns the CLI command for "rmdir".
  20. func NewRemoveDirCommand() cli.Command {
  21. return cli.Command{
  22. Name: "rmdir",
  23. Usage: "removes the key if it is an empty directory or a key-value pair",
  24. Action: func(c *cli.Context) {
  25. handleDir(c, removeDirCommandFunc)
  26. },
  27. }
  28. }
  29. // removeDirCommandFunc executes the "rmdir" command.
  30. func removeDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
  31. if len(c.Args()) == 0 {
  32. return nil, errors.New("Key required")
  33. }
  34. key := c.Args()[0]
  35. return client.DeleteDir(key)
  36. }