mirror of
https://github.com/mikefarah/yq.git
synced 2025-02-25 17:15:48 +00:00
Enabled multi document support for merge (first document only)
This commit is contained in:
parent
8ca85b1c64
commit
c38f19e0a9
@ -585,6 +585,25 @@ c:
|
|||||||
assertResult(t, expectedOutput, result.Output)
|
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) {
|
func TestMergeCmd_Error(t *testing.T) {
|
||||||
cmd := getRootCommand()
|
cmd := getRootCommand()
|
||||||
result := runCmd(cmd, "merge examples/data1.yaml")
|
result := runCmd(cmd, "merge examples/data1.yaml")
|
||||||
|
7
examples/multiple_docs_small.yaml
Normal file
7
examples/multiple_docs_small.yaml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
a: Easy! as one two three
|
||||||
|
---
|
||||||
|
another:
|
||||||
|
document: here
|
||||||
|
---
|
||||||
|
- 1
|
||||||
|
- 2
|
1
yq.go
1
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(&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().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
|
return cmdMerge
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user