mirror of
https://github.com/rancher/os.git
synced 2025-06-26 06:51:40 +00:00
Revert "Use yaml.Unmarshal to handle config arguments"
This commit is contained in:
parent
07faa92c7f
commit
8f6ee9ee05
@ -3,8 +3,9 @@ package config
|
||||
import (
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
yaml "github.com/cloudfoundry-incubator/candiedyaml"
|
||||
"github.com/rancher/os/util"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -86,7 +87,7 @@ func getOrSetVal(args string, data map[interface{}]interface{}, value interface{
|
||||
// Reached end, set the value
|
||||
if last && value != nil {
|
||||
if s, ok := value.(string); ok {
|
||||
value = unmarshalOrReturnString(s)
|
||||
value = DummyMarshall(s)
|
||||
}
|
||||
|
||||
t[part] = value
|
||||
@ -120,11 +121,28 @@ func getOrSetVal(args string, data map[interface{}]interface{}, value interface{
|
||||
return "", tData
|
||||
}
|
||||
|
||||
func unmarshalOrReturnString(value string) (result interface{}) {
|
||||
if err := yaml.Unmarshal([]byte(value), &result); err != nil {
|
||||
result = value
|
||||
func DummyMarshall(value string) interface{} {
|
||||
if strings.HasPrefix(value, "[") && strings.HasSuffix(value, "]") {
|
||||
result := []interface{}{}
|
||||
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{} {
|
||||
@ -149,7 +167,7 @@ outer:
|
||||
keys := strings.Split(kv[0], ".")
|
||||
for i, key := range keys {
|
||||
if i == len(keys)-1 {
|
||||
current[key] = unmarshalOrReturnString(value)
|
||||
current[key] = DummyMarshall(value)
|
||||
} else {
|
||||
if obj, ok := current[key]; ok {
|
||||
if newCurrent, ok := obj.(map[interface{}]interface{}); ok {
|
||||
|
Loading…
Reference in New Issue
Block a user