mirror of
https://github.com/rancher/os.git
synced 2025-09-02 23:34:57 +00:00
Use yaml.Unmarshal to handle config arguments
This commit is contained in:
@@ -3,9 +3,8 @@ package config
|
|||||||
import (
|
import (
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
|
||||||
|
yaml "github.com/cloudfoundry-incubator/candiedyaml"
|
||||||
"github.com/rancher/os/util"
|
"github.com/rancher/os/util"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -87,7 +86,7 @@ func getOrSetVal(args string, data map[interface{}]interface{}, value interface{
|
|||||||
// Reached end, set the value
|
// Reached end, set the value
|
||||||
if last && value != nil {
|
if last && value != nil {
|
||||||
if s, ok := value.(string); ok {
|
if s, ok := value.(string); ok {
|
||||||
value = DummyMarshall(s)
|
value = unmarshalOrReturnString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
t[part] = value
|
t[part] = value
|
||||||
@@ -121,28 +120,11 @@ func getOrSetVal(args string, data map[interface{}]interface{}, value interface{
|
|||||||
return "", tData
|
return "", tData
|
||||||
}
|
}
|
||||||
|
|
||||||
func DummyMarshall(value string) interface{} {
|
func unmarshalOrReturnString(value string) (result interface{}) {
|
||||||
if strings.HasPrefix(value, "[") && strings.HasSuffix(value, "]") {
|
if err := yaml.Unmarshal([]byte(value), &result); err != nil {
|
||||||
result := []interface{}{}
|
result = value
|
||||||
for _, i := range strings.Split(value[1:len(value)-1], ",") {
|
|
||||||
result = append(result, strings.TrimSpace(i))
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
if value == "true" {
|
|
||||||
return true
|
|
||||||
} else if value == "false" {
|
|
||||||
return false
|
|
||||||
} else if ok, _ := regexp.MatchString("^[0-9]+$", value); ok {
|
|
||||||
i, err := strconv.Atoi(value)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCmdline(cmdLine string) map[interface{}]interface{} {
|
func parseCmdline(cmdLine string) map[interface{}]interface{} {
|
||||||
@@ -167,7 +149,7 @@ outer:
|
|||||||
keys := strings.Split(kv[0], ".")
|
keys := strings.Split(kv[0], ".")
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
if i == len(keys)-1 {
|
if i == len(keys)-1 {
|
||||||
current[key] = DummyMarshall(value)
|
current[key] = unmarshalOrReturnString(value)
|
||||||
} else {
|
} else {
|
||||||
if obj, ok := current[key]; ok {
|
if obj, ok := current[key]; ok {
|
||||||
if newCurrent, ok := obj.(map[interface{}]interface{}); ok {
|
if newCurrent, ok := obj.(map[interface{}]interface{}); ok {
|
||||||
|
Reference in New Issue
Block a user