mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdctl: updatedir use etcd/client
This commit is contained in:
parent
f12ae45c6a
commit
ae1669de26
@ -16,12 +16,15 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd"
|
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
||||||
|
"github.com/coreos/etcd/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewUpdateDirCommand returns the CLI command for "updateDir".
|
// NewUpdateDirCommand returns the CLI command for "updatedir".
|
||||||
func NewUpdateDirCommand() cli.Command {
|
func NewUpdateDirCommand() cli.Command {
|
||||||
return cli.Command{
|
return cli.Command{
|
||||||
Name: "updatedir",
|
Name: "updatedir",
|
||||||
@ -30,18 +33,27 @@ func NewUpdateDirCommand() cli.Command {
|
|||||||
cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"},
|
cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"},
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) {
|
Action: func(c *cli.Context) {
|
||||||
handleDir(c, updateDirCommandFunc)
|
updatedirCommandFunc(c, mustNewKeyAPI(c))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateDirCommandFunc executes the "updateDir" command.
|
// updatedirCommandFunc executes the "updatedir" command.
|
||||||
func updateDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
func updatedirCommandFunc(c *cli.Context, ki client.KeysAPI) {
|
||||||
if len(c.Args()) == 0 {
|
if len(c.Args()) == 0 {
|
||||||
return nil, errors.New("Key required")
|
handleError(ExitBadArgs, errors.New("key required"))
|
||||||
}
|
}
|
||||||
key := c.Args()[0]
|
key := c.Args()[0]
|
||||||
|
value, err := argOrStdin(c.Args(), os.Stdin, 1)
|
||||||
|
if err != nil {
|
||||||
|
handleError(ExitBadArgs, errors.New("value required"))
|
||||||
|
}
|
||||||
|
|
||||||
ttl := c.Int("ttl")
|
ttl := c.Int("ttl")
|
||||||
|
|
||||||
return client.UpdateDir(key, uint64(ttl))
|
// TODO: handle transport timeout
|
||||||
|
_, err = ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: client.PrevExist})
|
||||||
|
if err != nil {
|
||||||
|
handleError(ExitServerError, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user