etcdctl: update use etcd/client
This commit is contained in:
@ -17,9 +17,11 @@ package command
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewUpdateCommand returns the CLI command for "update".
|
// NewUpdateCommand returns the CLI command for "update".
|
||||||
@ -31,23 +33,29 @@ func NewUpdateCommand() 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) {
|
||||||
handleKey(c, updateCommandFunc)
|
updateCommandFunc(c, mustNewKeyAPI(c))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateCommandFunc executes the "update" command.
|
// updateCommandFunc executes the "update" command.
|
||||||
func updateCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
func updateCommandFunc(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)
|
value, err := argOrStdin(c.Args(), os.Stdin, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("Value required")
|
handleError(ExitBadArgs, errors.New("value required"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ttl := c.Int("ttl")
|
ttl := c.Int("ttl")
|
||||||
|
|
||||||
return client.Update(key, value, uint64(ttl))
|
// TODO: handle transport timeout
|
||||||
|
resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevExist})
|
||||||
|
if err != nil {
|
||||||
|
handleError(ExitServerError, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
printResponseKey(resp, c.GlobalString("output"))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user