Enabled multi document support for merge (first document only)

This commit is contained in:
Mike Farah 2018-06-15 16:48:36 +10:00
parent 8ca85b1c64
commit c38f19e0a9
3 changed files with 27 additions and 0 deletions

View File

@ -585,6 +585,25 @@ c:
assertResult(t, expectedOutput, result.Output)
}
func TestMergeCmd_Multi(t *testing.T) {
cmd := getRootCommand()
result := runCmd(cmd, "merge -d1 examples/multiple_docs_small.yaml examples/data2.yaml")
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `a: Easy! as one two three
---
a: other
another:
document: here
c:
test: 1
---
- 1
- 2`
assertResult(t, expectedOutput, strings.Trim(result.Output, "\n "))
}
func TestMergeCmd_Error(t *testing.T) {
cmd := getRootCommand()
result := runCmd(cmd, "merge examples/data1.yaml")

View File

@ -0,0 +1,7 @@
a: Easy! as one two three
---
another:
document: here
---
- 1
- 2

1
yq.go
View File

@ -200,6 +200,7 @@ If overwrite flag is set then existing values will be overwritten using the valu
}
cmdMerge.PersistentFlags().BoolVarP(&writeInplace, "inplace", "i", false, "update the yaml file inplace")
cmdMerge.PersistentFlags().BoolVarP(&overwriteFlag, "overwrite", "x", false, "update the yaml file by overwriting existing values")
cmdMerge.PersistentFlags().IntVarP(&docIndex, "doc", "d", 0, "process document index number (0 based)")
return cmdMerge
}