From abbd3466598d825f516983415cbed4bad2b5dc31 Mon Sep 17 00:00:00 2001 From: therealplato Date: Wed, 2 May 2018 20:41:20 +1200 Subject: [PATCH] read: retrieve entire subdocument --- yq.go | 2 +- yq_test.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/yq.go b/yq.go index 06838189..c2eb92e0 100644 --- a/yq.go +++ b/yq.go @@ -181,7 +181,7 @@ func readProperty(cmd *cobra.Command, args []string) error { return nil } -var regexpSubdocPath = regexp.MustCompile(`^@(\d+)\.(.*)$`) +var regexpSubdocPath = regexp.MustCompile(`^@(\d+)(?:\.)?(.*)?$`) func read(args []string) (interface{}, error) { var ( diff --git a/yq_test.go b/yq_test.go index b2b764f9..704eb999 100644 --- a/yq_test.go +++ b/yq_test.go @@ -43,7 +43,15 @@ func TestReadMultipleDocuments(t *testing.T) { result, _ := read([]string{"examples/multidocument.yaml", "b.c"}) 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"}) assertResult(t, 1, result)