mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Can create arrays
This commit is contained in:
parent
5514d2300b
commit
1ed8e7017e
13
yaml.go
13
yaml.go
@ -160,9 +160,18 @@ func newYaml(args []string) interface{} {
|
||||
writeCommands[0] = yaml.MapItem{Key: args[0], Value: parseValue(args[1])}
|
||||
}
|
||||
|
||||
parsedData := make(yaml.MapSlice, 0)
|
||||
var parsedData yaml.MapSlice
|
||||
var prependCommand = ""
|
||||
var isArray = strings.HasPrefix(writeCommands[0].Key.(string), "[")
|
||||
if isArray {
|
||||
item := yaml.MapItem{Key: "thing", Value: make(yaml.MapSlice, 0)}
|
||||
parsedData = yaml.MapSlice{item}
|
||||
prependCommand = "thing"
|
||||
} else {
|
||||
parsedData = make(yaml.MapSlice, 0)
|
||||
}
|
||||
|
||||
return updateParsedData(parsedData, writeCommands, "")
|
||||
return updateParsedData(parsedData, writeCommands, prependCommand)
|
||||
}
|
||||
|
||||
func writeProperty(cmd *cobra.Command, args []string) {
|
||||
|
@ -55,6 +55,14 @@ func TestNewYaml(t *testing.T) {
|
||||
formattedResult)
|
||||
}
|
||||
|
||||
func TestNewYamlArray(t *testing.T) {
|
||||
result := newYaml([]string{"[0].cat", "meow"})
|
||||
formattedResult := fmt.Sprintf("%v", result)
|
||||
assertResult(t,
|
||||
"[[{cat meow}]]",
|
||||
formattedResult)
|
||||
}
|
||||
|
||||
func TestUpdateYaml(t *testing.T) {
|
||||
result := updateYaml([]string{"sample.yaml", "b.c", "3"})
|
||||
formattedResult := fmt.Sprintf("%v", result)
|
||||
|
Loading…
Reference in New Issue
Block a user