1
0
mirror of https://github.com/rancher/os.git synced 2025-08-27 18:59:17 +00:00

Implement rancherctl config get

This commit is contained in:
Darren Shepherd 2015-02-17 15:32:15 -07:00
parent 5ca7f4504d
commit e877d5804f

View File

@ -3,8 +3,10 @@ package control
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"strings"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"gopkg.in/yaml.v2"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/rancherio/os/config" "github.com/rancherio/os/config"
@ -16,6 +18,7 @@ func configSubcommands() []cli.Command {
{ {
Name: "get", Name: "get",
Usage: "get value", Usage: "get value",
Action: configGet,
}, },
{ {
Name: "import", Name: "import",
@ -39,12 +42,53 @@ func configSubcommands() []cli.Command {
} }
} }
func configGet(c *cli.Context) {
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
content, err := cfg.Dump()
if err != nil {
log.Fatal(err)
}
data := make(map[interface{}]interface{})
yaml.Unmarshal([]byte(content), data)
arg := c.Args().Get(0)
if arg == "" {
fmt.Println("")
return
}
parts := strings.Split(arg, ".")
for i, part := range parts {
if val, ok := data[part]; ok {
if i+1 == len(parts) {
fmt.Println(val)
} else {
if newData, ok := val.(map[interface{}]interface{}); ok {
data = newData
} else {
fmt.Println(val)
break
}
}
} else {
fmt.Println("2")
break
}
}
}
func configSave(c *cli.Context) { func configSave(c *cli.Context) {
cfg, err := config.LoadConfig() cfg, err := config.LoadConfig()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
//TODO: why doesn't this work
for _, c := range cfg.SystemContainers { for _, c := range cfg.SystemContainers {
container := docker.NewContainer("", &c) container := docker.NewContainer("", &c)
if container.Err != nil { if container.Err != nil {