mkdir_command.go 810 B

123456789101112131415161718192021222324252627282930313233
  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. // NewMakeDirCommand returns the CLI command for "mkdir".
  8. func NewMakeDirCommand() cli.Command {
  9. return cli.Command{
  10. Name: "mkdir",
  11. Usage: "make a new directory",
  12. Flags: []cli.Flag{
  13. cli.IntFlag{"ttl", 0, "key time-to-live"},
  14. },
  15. Action: func(c *cli.Context) {
  16. handleDir(c, makeDirCommandFunc)
  17. },
  18. }
  19. }
  20. // makeDirCommandFunc executes the "mkdir" command.
  21. func makeDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
  22. if len(c.Args()) == 0 {
  23. return nil, errors.New("Key required")
  24. }
  25. key := c.Args()[0]
  26. ttl := c.Int("ttl")
  27. return client.CreateDir(key, uint64(ttl))
  28. }