mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-08 06:45:38 +00:00
read: retrieve entire subdocument
This commit is contained in:
parent
fbeeaba875
commit
abbd346659
2
yq.go
2
yq.go
@ -181,7 +181,7 @@ func readProperty(cmd *cobra.Command, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var regexpSubdocPath = regexp.MustCompile(`^@(\d+)\.(.*)$`)
|
var regexpSubdocPath = regexp.MustCompile(`^@(\d+)(?:\.)?(.*)?$`)
|
||||||
|
|
||||||
func read(args []string) (interface{}, error) {
|
func read(args []string) (interface{}, error) {
|
||||||
var (
|
var (
|
||||||
|
|||||||
10
yq_test.go
10
yq_test.go
@ -43,7 +43,15 @@ func TestReadMultipleDocuments(t *testing.T) {
|
|||||||
result, _ := read([]string{"examples/multidocument.yaml", "b.c"})
|
result, _ := read([]string{"examples/multidocument.yaml", "b.c"})
|
||||||
assertResult(t, 1, result)
|
assertResult(t, 1, result)
|
||||||
})
|
})
|
||||||
t.Run("multiple documents with leading @n reads from document n", func(t *testing.T) {
|
t.Run("multiple documents with @n path reads document n", func(t *testing.T) {
|
||||||
|
result, _ := read([]string{"examples/multidocument.yaml", "@0"})
|
||||||
|
actual, err := yamlToString(result)
|
||||||
|
assertNilErr(t, err)
|
||||||
|
assertResult(t, `a: Document One
|
||||||
|
b:
|
||||||
|
c: 1`, actual)
|
||||||
|
})
|
||||||
|
t.Run("multiple documents with leading @n path reads path from document n", func(t *testing.T) {
|
||||||
result, _ := read([]string{"examples/multidocument.yaml", "@0.b.c"})
|
result, _ := read([]string{"examples/multidocument.yaml", "@0.b.c"})
|
||||||
assertResult(t, 1, result)
|
assertResult(t, 1, result)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user