mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
Prefix now supports arrays
This commit is contained in:
parent
8a3fb32f36
commit
16bde80334
@ -360,6 +360,26 @@ func TestPrefixCmd(t *testing.T) {
|
||||
assertResult(t, expectedOutput, result.Output)
|
||||
}
|
||||
|
||||
func TestPrefixCmdArray(t *testing.T) {
|
||||
content := `b:
|
||||
c: 3
|
||||
`
|
||||
filename := writeTempYamlFile(content)
|
||||
defer removeTempYamlFile(filename)
|
||||
|
||||
cmd := getRootCommand()
|
||||
result := runCmd(cmd, fmt.Sprintf("prefix %s [0].d.[1]", filename))
|
||||
if result.Error != nil {
|
||||
t.Error(result.Error)
|
||||
}
|
||||
expectedOutput := `- d:
|
||||
- null
|
||||
- b:
|
||||
c: 3
|
||||
`
|
||||
assertResult(t, expectedOutput, result.Output)
|
||||
}
|
||||
|
||||
func TestPrefixCmd_MultiLayer(t *testing.T) {
|
||||
content := `b:
|
||||
c: 3
|
||||
|
5
yq.go
5
yq.go
@ -440,9 +440,8 @@ func prefixProperty(cmd *cobra.Command, args []string) error {
|
||||
log.Debugf("Prefixing %v to doc %v", paths, currentIndex)
|
||||
var mapDataBucket = dataBucket
|
||||
for _, key := range paths {
|
||||
nestedBucket := make(map[string]interface{})
|
||||
nestedBucket[key] = mapDataBucket
|
||||
mapDataBucket = nestedBucket
|
||||
singlePath := []string{key}
|
||||
mapDataBucket = updatedChildValue(nil, singlePath, mapDataBucket)
|
||||
}
|
||||
return mapDataBucket, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user