Skip to content

Commit c1b8033

Browse files
author
mfarah
committed
Now attempts to parse the write value type
1 parent 364c1a8 commit c1b8033

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

yaml.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,39 @@ func writeProperty(c *cli.Context) {
6161
var parsedData map[interface{}]interface{}
6262
readYaml(c, &parsedData)
6363

64-
if len(c.Args()) != 3 {
64+
if len(c.Args()) < 3 {
6565
log.Fatalf("Must provide <filename> <path_to_update> <value>")
6666
}
6767

68+
var forceString bool
69+
if len(c.Args()) == 4 {
70+
forceString = true
71+
}
72+
6873
var path = c.Args()[1]
6974
var paths = strings.Split(path, ".")
7075

71-
write(parsedData, paths[0], paths[1:len(paths)], c.Args()[2])
76+
write(parsedData, paths[0], paths[1:len(paths)], getValue(c.Args()[2], forceString))
7277

7378
printYaml(parsedData, c.Bool("trim"))
7479
}
7580

81+
func getValue(argument string, forceString bool) interface{} {
82+
var value, err interface{}
83+
84+
if !forceString {
85+
value, err = strconv.ParseFloat(argument, 64)
86+
if err == nil {
87+
return value
88+
}
89+
value, err = strconv.ParseBool(argument)
90+
if err == nil {
91+
return value
92+
}
93+
}
94+
return argument
95+
}
96+
7697
func printYaml(context interface{}, trim bool) {
7798
out, err := yaml.Marshal(context)
7899
if err != nil {

0 commit comments

Comments
 (0)