mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdctl: make setdir/mkdir use etcd/client
This commit is contained in:
parent
db4b18aee3
commit
9d9c3a7180
@ -16,9 +16,11 @@ package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// NewMakeDirCommand returns the CLI command for "mkdir".
|
||||
@ -30,18 +32,23 @@ func NewMakeDirCommand() cli.Command {
|
||||
cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"},
|
||||
},
|
||||
Action: func(c *cli.Context) {
|
||||
handleDir(c, makeDirCommandFunc)
|
||||
mkdirCommandFunc(c, mustNewKeyAPI(c), client.PrevNoExist)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// makeDirCommandFunc executes the "mkdir" command.
|
||||
func makeDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
||||
// mkdirCommandFunc executes the "mkdir" command.
|
||||
func mkdirCommandFunc(c *cli.Context, ki client.KeysAPI, prevExist client.PrevExistType) {
|
||||
if len(c.Args()) == 0 {
|
||||
return nil, errors.New("key required")
|
||||
handleError(ExitBadArgs, errors.New("key required"))
|
||||
}
|
||||
|
||||
key := c.Args()[0]
|
||||
ttl := c.Int("ttl")
|
||||
|
||||
return client.CreateDir(key, uint64(ttl))
|
||||
// TODO: handle transport timeout
|
||||
_, err := ki.Set(context.TODO(), key, "", &client.SetOptions{TTL: time.Second * time.Duration(ttl), Dir: true, PrevExist: prevExist})
|
||||
if err != nil {
|
||||
handleError(ExitServerError, err)
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,8 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"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/client"
|
||||
)
|
||||
|
||||
// NewSetDirCommand returns the CLI command for "setDir".
|
||||
@ -30,18 +28,7 @@ func NewSetDirCommand() cli.Command {
|
||||
cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"},
|
||||
},
|
||||
Action: func(c *cli.Context) {
|
||||
handleDir(c, setDirCommandFunc)
|
||||
mkdirCommandFunc(c, mustNewKeyAPI(c), client.PrevIgnore)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// setDirCommandFunc executes the "setDir" command.
|
||||
func setDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
||||
if len(c.Args()) == 0 {
|
||||
return nil, errors.New("Key required")
|
||||
}
|
||||
key := c.Args()[0]
|
||||
ttl := c.Int("ttl")
|
||||
|
||||
return client.SetDir(key, uint64(ttl))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user