diff --git a/commands_test.go b/commands_test.go index c0cf43e3..88b777a6 100644 --- a/commands_test.go +++ b/commands_test.go @@ -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") diff --git a/examples/multiple_docs_small.yaml b/examples/multiple_docs_small.yaml new file mode 100644 index 00000000..86035cce --- /dev/null +++ b/examples/multiple_docs_small.yaml @@ -0,0 +1,7 @@ +a: Easy! as one two three +--- +another: + document: here +--- +- 1 +- 2 \ No newline at end of file diff --git a/yq.go b/yq.go index 359b576c..e12b6e68 100644 --- a/yq.go +++ b/yq.go @@ -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 }