1
0
mirror of https://github.com/rancher/os.git synced 2025-06-28 15:56:58 +00:00

Revert "Use yaml.Unmarshal to handle config arguments"

This commit is contained in:
Josh Curl 2016-04-05 10:00:12 -07:00
parent 07faa92c7f
commit 8f6ee9ee05

View File

@ -3,8 +3,9 @@ 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"
) )
@ -86,7 +87,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 = unmarshalOrReturnString(s) value = DummyMarshall(s)
} }
t[part] = value t[part] = value
@ -120,11 +121,28 @@ func getOrSetVal(args string, data map[interface{}]interface{}, value interface{
return "", tData return "", tData
} }
func unmarshalOrReturnString(value string) (result interface{}) { func DummyMarshall(value string) interface{} {
if err := yaml.Unmarshal([]byte(value), &result); err != nil { if strings.HasPrefix(value, "[") && strings.HasSuffix(value, "]") {
result = value result := []interface{}{}
for _, i := range strings.Split(value[1:len(value)-1], ",") {
result = append(result, strings.TrimSpace(i))
} }
return return result
}
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{} {
@ -149,7 +167,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] = unmarshalOrReturnString(value) current[key] = DummyMarshall(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 {