Now attempts to parse the write value type

This commit is contained in:
mfarah 2015-10-01 10:41:43 +10:00
parent 364c1a8af3
commit c1b803364a

25
yaml.go
View File

@ -61,18 +61,39 @@ func writeProperty(c *cli.Context) {
var parsedData map[interface{}]interface{}
readYaml(c, &parsedData)
if len(c.Args()) != 3 {
if len(c.Args()) < 3 {
log.Fatalf("Must provide <filename> <path_to_update> <value>")
}
var forceString bool
if len(c.Args()) == 4 {
forceString = true
}
var path = c.Args()[1]
var paths = strings.Split(path, ".")
write(parsedData, paths[0], paths[1:len(paths)], c.Args()[2])
write(parsedData, paths[0], paths[1:len(paths)], getValue(c.Args()[2], forceString))
printYaml(parsedData, c.Bool("trim"))
}
func getValue(argument string, forceString bool) interface{} {
var value, err interface{}
if !forceString {
value, err = strconv.ParseFloat(argument, 64)
if err == nil {
return value
}
value, err = strconv.ParseBool(argument)
if err == nil {
return value
}
}
return argument
}
func printYaml(context interface{}, trim bool) {
out, err := yaml.Marshal(context)
if err != nil {