File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -160,9 +160,18 @@ func newYaml(args []string) interface{} {
160
160
writeCommands [0 ] = yaml.MapItem {Key : args [0 ], Value : parseValue (args [1 ])}
161
161
}
162
162
163
- parsedData := make (yaml.MapSlice , 0 )
163
+ var parsedData yaml.MapSlice
164
+ var prependCommand = ""
165
+ var isArray = strings .HasPrefix (writeCommands [0 ].Key .(string ), "[" )
166
+ if isArray {
167
+ item := yaml.MapItem {Key : "thing" , Value : make (yaml.MapSlice , 0 )}
168
+ parsedData = yaml.MapSlice {item }
169
+ prependCommand = "thing"
170
+ } else {
171
+ parsedData = make (yaml.MapSlice , 0 )
172
+ }
164
173
165
- return updateParsedData (parsedData , writeCommands , "" )
174
+ return updateParsedData (parsedData , writeCommands , prependCommand )
166
175
}
167
176
168
177
func writeProperty (cmd * cobra.Command , args []string ) {
Original file line number Diff line number Diff line change @@ -55,6 +55,14 @@ func TestNewYaml(t *testing.T) {
55
55
formattedResult )
56
56
}
57
57
58
+ func TestNewYamlArray (t * testing.T ) {
59
+ result := newYaml ([]string {"[0].cat" , "meow" })
60
+ formattedResult := fmt .Sprintf ("%v" , result )
61
+ assertResult (t ,
62
+ "[[{cat meow}]]" ,
63
+ formattedResult )
64
+ }
65
+
58
66
func TestUpdateYaml (t * testing.T ) {
59
67
result := updateYaml ([]string {"sample.yaml" , "b.c" , "3" })
60
68
formattedResult := fmt .Sprintf ("%v" , result )
You can’t perform that action at this time.
0 commit comments