etcdctl: minor cleanup
This commit is contained in:
@ -19,7 +19,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/coreos/go-etcd/etcd"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// printKey writes the etcd response to STDOUT in the given format.
|
// printKey writes the etcd response to STDOUT in the given format.
|
||||||
|
@ -55,7 +55,7 @@ func printGet(resp *etcd.Response, format string) {
|
|||||||
// getCommandFunc executes the "get" command.
|
// getCommandFunc executes the "get" command.
|
||||||
func getCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
func getCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
||||||
if len(c.Args()) == 0 {
|
if len(c.Args()) == 0 {
|
||||||
return nil, errors.New("Key required")
|
return nil, errors.New("key required")
|
||||||
}
|
}
|
||||||
key := c.Args()[0]
|
key := c.Args()[0]
|
||||||
sorted := c.Bool("sort")
|
sorted := c.Bool("sort")
|
||||||
|
@ -39,12 +39,12 @@ func NewMakeCommand() cli.Command {
|
|||||||
// makeCommandFunc executes the "make" command.
|
// makeCommandFunc executes the "make" command.
|
||||||
func makeCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
func makeCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
||||||
if len(c.Args()) == 0 {
|
if len(c.Args()) == 0 {
|
||||||
return nil, errors.New("Key required")
|
return nil, 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")
|
return nil, errors.New("value required")
|
||||||
}
|
}
|
||||||
|
|
||||||
ttl := c.Int("ttl")
|
ttl := c.Int("ttl")
|
||||||
|
@ -38,7 +38,7 @@ func NewMakeDirCommand() cli.Command {
|
|||||||
// makeDirCommandFunc executes the "mkdir" command.
|
// makeDirCommandFunc executes the "mkdir" command.
|
||||||
func makeDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
func makeDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
||||||
if len(c.Args()) == 0 {
|
if len(c.Args()) == 0 {
|
||||||
return nil, errors.New("Key required")
|
return nil, errors.New("key required")
|
||||||
}
|
}
|
||||||
key := c.Args()[0]
|
key := c.Args()[0]
|
||||||
ttl := c.Int("ttl")
|
ttl := c.Int("ttl")
|
||||||
|
@ -41,7 +41,7 @@ func NewRemoveCommand() cli.Command {
|
|||||||
// removeCommandFunc executes the "rm" command.
|
// removeCommandFunc executes the "rm" command.
|
||||||
func removeCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
func removeCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
||||||
if len(c.Args()) == 0 {
|
if len(c.Args()) == 0 {
|
||||||
return nil, errors.New("Key required")
|
return nil, errors.New("key required")
|
||||||
}
|
}
|
||||||
key := c.Args()[0]
|
key := c.Args()[0]
|
||||||
recursive := c.Bool("recursive")
|
recursive := c.Bool("recursive")
|
||||||
|
@ -35,7 +35,7 @@ func NewRemoveDirCommand() cli.Command {
|
|||||||
// removeDirCommandFunc executes the "rmdir" command.
|
// removeDirCommandFunc executes the "rmdir" command.
|
||||||
func removeDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
func removeDirCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
||||||
if len(c.Args()) == 0 {
|
if len(c.Args()) == 0 {
|
||||||
return nil, errors.New("Key required")
|
return nil, errors.New("key required")
|
||||||
}
|
}
|
||||||
key := c.Args()[0]
|
key := c.Args()[0]
|
||||||
|
|
||||||
|
@ -41,12 +41,12 @@ func NewSetCommand() cli.Command {
|
|||||||
// setCommandFunc executes the "set" command.
|
// setCommandFunc executes the "set" command.
|
||||||
func setCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
func setCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
|
||||||
if len(c.Args()) == 0 {
|
if len(c.Args()) == 0 {
|
||||||
return nil, errors.New("Key required")
|
return nil, 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")
|
return nil, errors.New("value required")
|
||||||
}
|
}
|
||||||
|
|
||||||
ttl := c.Int("ttl")
|
ttl := c.Int("ttl")
|
||||||
@ -55,7 +55,6 @@ func setCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error)
|
|||||||
|
|
||||||
if prevValue == "" && prevIndex == 0 {
|
if prevValue == "" && prevIndex == 0 {
|
||||||
return client.Set(key, value, uint64(ttl))
|
return client.Set(key, value, uint64(ttl))
|
||||||
} else {
|
|
||||||
return client.CompareAndSwap(key, value, uint64(ttl), prevValue, uint64(prevIndex))
|
|
||||||
}
|
}
|
||||||
|
return client.CompareAndSwap(key, value, uint64(ttl), prevValue, uint64(prevIndex))
|
||||||
}
|
}
|
||||||
|
@ -111,5 +111,4 @@ func getTransport(c *cli.Context) (*http.Transport, error) {
|
|||||||
KeyFile: keyfile,
|
KeyFile: keyfile,
|
||||||
}
|
}
|
||||||
return transport.NewTransport(tls)
|
return transport.NewTransport(tls)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user