update_dir_command.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // NewUpdateDirCommand returns the CLI command for "updateDir".
  20. func NewUpdateDirCommand() cli.Command {
  21. return cli.Command{
  22. Name: "updatedir",
  23. Usage: "update an existing directory",
  24. Flags: []cli.Flag{
  25. cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"},
  26. },
  27. Action: func(c *cli.Context) {
  28. handleDir(c, updateDirCommandFunc)
  29. },
  30. }
  31. }
  32. // updateDirCommandFunc executes the "updateDir" command.
  33. func updateDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
  34. if len(c.Args()) == 0 {
  35. return nil, errors.New("Key required")
  36. }
  37. key := c.Args()[0]
  38. ttl := c.Int("ttl")
  39. return client.UpdateDir(key, uint64(ttl))
  40. }