Skip to content

Commit

Permalink
feat(deisctl): add config rm
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua-Anderson committed May 27, 2015
1 parent 4e423c0 commit 97dfc44
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions deisctl/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,13 @@ to a private key.
Usage:
deisctl config <target> get [<key>...]
deisctl config <target> set <key=val>...
deisctl config <target> rm [<key>...]
Examples:
deisctl config platform set domain=mydomain.com
deisctl config platform set sshPrivateKey=$HOME/.ssh/deis
deisctl config controller get webEnabled
deisctl config controller rm webEnabled
`
// parse command-line arguments
args, err := docopt.Parse(usage, argv, true, "", false)
Expand Down
14 changes: 14 additions & 0 deletions deisctl/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func doConfig(args map[string]interface{}) error {
var vals []string
if args["set"] == true {
vals, err = doConfigSet(client, rootPath, args["<key=val>"].([]string))
} else if args["rm"] == true {
vals, err = doConfigRm(client, rootPath, args["<key>"].([]string))
} else {
vals, err = doConfigGet(client, rootPath, args["<key>"].([]string))
}
Expand Down Expand Up @@ -104,6 +106,18 @@ func doConfigGet(client *etcdClient, root string, keys []string) ([]string, erro
return result, nil
}

func doConfigRm(client *etcdClient, root string, keys []string) ([]string, error) {
var result []string
for _, k := range keys {
err := client.Delete(root + k)
if err != nil {
return result, err
}
result = append(result, k)
}
return result, nil
}

// valueForPath returns the canonical value for a user-defined path and value
func valueForPath(path string, v string) (string, error) {

Expand Down
5 changes: 5 additions & 0 deletions deisctl/config/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (c *etcdClient) Get(key string) (string, error) {
return resp.Node.Value, nil
}

func (c *etcdClient) Delete(key string) error {
_, err := c.etcd.Delete(key, false)
return err
}

func (c *etcdClient) Set(key string, value string) (string, error) {
resp, err := c.etcd.Set(key, value, 0) // don't use TTLs
if err != nil {
Expand Down

0 comments on commit 97dfc44

Please sign in to comment.