From 28909bbc5ac0805b14899cee0a3866477d97c0c2 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 5 Jun 2023 14:46:59 -0700 Subject: [PATCH] Recurse doc problem --- pkg/yqlib/doc/operators/comment-operators.md | 12 ++++++++++-- pkg/yqlib/doc/operators/recursive-descent-glob.md | 5 +++++ pkg/yqlib/operator_recursive_descent.go | 5 ++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/yqlib/doc/operators/comment-operators.md b/pkg/yqlib/doc/operators/comment-operators.md index 2c1e1d02..08964e52 100644 --- a/pkg/yqlib/doc/operators/comment-operators.md +++ b/pkg/yqlib/doc/operators/comment-operators.md @@ -75,6 +75,11 @@ yq '[... | {"p": path | join("."), "isKey": is_key, "hc": headComment, "lc": lin ``` will output ```yaml +- p: "" + isKey: false + hc: "" + lc: "" + fc: "" - p: "" isKey: false hc: "" @@ -135,6 +140,11 @@ yq '[... | {"p": path | join("."), "isKey": is_key, "hc": headComment, "lc": lin ``` will output ```yaml +- p: "" + isKey: false + hc: "" + lc: "" + fc: "" - p: "" isKey: false hc: "" @@ -259,8 +269,6 @@ yq '... comments=""' sample.yml ``` will output ```yaml -# hi - a: cat b: ``` diff --git a/pkg/yqlib/doc/operators/recursive-descent-glob.md b/pkg/yqlib/doc/operators/recursive-descent-glob.md index cfcb7dae..3cfcf407 100644 --- a/pkg/yqlib/doc/operators/recursive-descent-glob.md +++ b/pkg/yqlib/doc/operators/recursive-descent-glob.md @@ -31,6 +31,7 @@ yq '..' sample.yml will output ```yaml a: frog +a: frog frog ``` @@ -92,6 +93,7 @@ yq '...' sample.yml will output ```yaml a: frog +a: frog a frog ``` @@ -109,6 +111,9 @@ yq '[..]' sample.yml ``` will output ```yaml +- a: &cat + c: frog + b: *cat - a: &cat c: frog b: *cat diff --git a/pkg/yqlib/operator_recursive_descent.go b/pkg/yqlib/operator_recursive_descent.go index e0e5566d..2da709da 100644 --- a/pkg/yqlib/operator_recursive_descent.go +++ b/pkg/yqlib/operator_recursive_descent.go @@ -25,7 +25,10 @@ func recursiveDecent(results *list.List, context Context, preferences recursiveD for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) - candidate = candidate.unwrapDocument() + if candidate.Kind == DocumentNode { + results.PushBack(candidate) + candidate = candidate.unwrapDocument() + } log.Debugf("Recursive Decent, added %v", NodeToString(candidate)) results.PushBack(candidate)