Skip to content

Commit 97dfc44

Browse files
feat(deisctl): add config rm
1 parent 4e423c0 commit 97dfc44

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

deisctl/cmd/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,13 @@ to a private key.
511511
Usage:
512512
deisctl config <target> get [<key>...]
513513
deisctl config <target> set <key=val>...
514+
deisctl config <target> rm [<key>...]
514515
515516
Examples:
516517
deisctl config platform set domain=mydomain.com
517518
deisctl config platform set sshPrivateKey=$HOME/.ssh/deis
518519
deisctl config controller get webEnabled
520+
deisctl config controller rm webEnabled
519521
`
520522
// parse command-line arguments
521523
args, err := docopt.Parse(usage, argv, true, "", false)

deisctl/config/config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func doConfig(args map[string]interface{}) error {
5151
var vals []string
5252
if args["set"] == true {
5353
vals, err = doConfigSet(client, rootPath, args["<key=val>"].([]string))
54+
} else if args["rm"] == true {
55+
vals, err = doConfigRm(client, rootPath, args["<key>"].([]string))
5456
} else {
5557
vals, err = doConfigGet(client, rootPath, args["<key>"].([]string))
5658
}
@@ -104,6 +106,18 @@ func doConfigGet(client *etcdClient, root string, keys []string) ([]string, erro
104106
return result, nil
105107
}
106108

109+
func doConfigRm(client *etcdClient, root string, keys []string) ([]string, error) {
110+
var result []string
111+
for _, k := range keys {
112+
err := client.Delete(root + k)
113+
if err != nil {
114+
return result, err
115+
}
116+
result = append(result, k)
117+
}
118+
return result, nil
119+
}
120+
107121
// valueForPath returns the canonical value for a user-defined path and value
108122
func valueForPath(path string, v string) (string, error) {
109123

deisctl/config/etcd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func (c *etcdClient) Get(key string) (string, error) {
4242
return resp.Node.Value, nil
4343
}
4444

45+
func (c *etcdClient) Delete(key string) error {
46+
_, err := c.etcd.Delete(key, false)
47+
return err
48+
}
49+
4550
func (c *etcdClient) Set(key string, value string) (string, error) {
4651
resp, err := c.etcd.Set(key, value, 0) // don't use TTLs
4752
if err != nil {

0 commit comments

Comments
 (0)