mirror of
https://github.com/rancher/os.git
synced 2025-08-25 17:59:17 +00:00
Implement rancherctl config get
This commit is contained in:
parent
5ca7f4504d
commit
e877d5804f
@ -3,8 +3,10 @@ package control
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/rancherio/os/config"
|
||||
@ -14,8 +16,9 @@ import (
|
||||
func configSubcommands() []cli.Command {
|
||||
return []cli.Command{
|
||||
{
|
||||
Name: "get",
|
||||
Usage: "get value",
|
||||
Name: "get",
|
||||
Usage: "get value",
|
||||
Action: configGet,
|
||||
},
|
||||
{
|
||||
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) {
|
||||
cfg, err := config.LoadConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
//TODO: why doesn't this work
|
||||
for _, c := range cfg.SystemContainers {
|
||||
container := docker.NewContainer("", &c)
|
||||
if container.Err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user