update_dir_command.go 860 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. // NewUpdateDirCommand returns the CLI command for "updateDir".
  8. func NewUpdateDirCommand() cli.Command {
  9. return cli.Command{
  10. Name: "updatedir",
  11. Usage: "update an existing directory",
  12. Flags: []cli.Flag{
  13. cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"},
  14. },
  15. Action: func(c *cli.Context) {
  16. handleDir(c, updateDirCommandFunc)
  17. },
  18. }
  19. }
  20. // updateDirCommandFunc executes the "updateDir" command.
  21. func updateDirCommandFunc(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.UpdateDir(key, uint64(ttl))
  28. }