From c2000a446bee174dab5d7d72e723379982375640 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Tue, 18 Apr 2017 15:55:43 +1000 Subject: [PATCH] Fixed writeCommands to maintain the same execution as was read in --- yaml.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/yaml.go b/yaml.go index 5ea8312e..f90d47bf 100644 --- a/yaml.go +++ b/yaml.go @@ -140,24 +140,19 @@ func newProperty(cmd *cobra.Command, args []string) { } func newYaml(args []string) interface{} { - var writeCommands map[string]interface{} + var writeCommands yaml.MapSlice if writeScript != "" { readData(writeScript, &writeCommands, false) } else if len(args) < 2 { die("Must provide ") } else { - writeCommands = make(map[string]interface{}) - writeCommands[args[0]] = parseValue(args[1]) + writeCommands = make(yaml.MapSlice, 1) + writeCommands[0] = yaml.MapItem{Key: args[0], Value: parseValue(args[1])} } parsedData := make(yaml.MapSlice, 0) - for path, value := range writeCommands { - var paths = parsePath(path) - parsedData = writeMap(parsedData, paths, value) - } - - return parsedData + return updateParsedData(parsedData, writeCommands) } func writeProperty(cmd *cobra.Command, args []string) { @@ -172,26 +167,31 @@ func writeProperty(cmd *cobra.Command, args []string) { } } +func updateParsedData(parsedData yaml.MapSlice, writeCommands yaml.MapSlice) yaml.MapSlice { + for _, entry := range writeCommands { + path := entry.Key + value := entry.Value + var paths = parsePath(path.(string)) + parsedData = writeMap(parsedData, paths, value) + } + return parsedData +} + func updateYaml(args []string) interface{} { - var writeCommands map[string]interface{} + var writeCommands yaml.MapSlice if writeScript != "" { readData(writeScript, &writeCommands, false) } else if len(args) < 3 { die("Must provide ") } else { - writeCommands = make(map[string]interface{}) - writeCommands[args[1]] = parseValue(args[2]) + writeCommands = make(yaml.MapSlice, 1) + writeCommands[0] = yaml.MapItem{Key: args[1], Value: parseValue(args[2])} } var parsedData yaml.MapSlice readData(args[0], &parsedData, inputJSON) - for path, value := range writeCommands { - var paths = parsePath(path) - parsedData = writeMap(parsedData, paths, value) - } - - return parsedData + return updateParsedData(parsedData, writeCommands) } func parseValue(argument string) interface{} {