From 7e09a66b0b11b633873a916c823645a08da4c406 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Wed, 24 Nov 2021 10:59:19 +1100 Subject: [PATCH] Fixing comments --- pkg/yqlib/doc/comment-operators.md | 2 +- pkg/yqlib/doc/headers/parent.md | 3 +++ pkg/yqlib/doc/parent.md | 8 +++++++- pkg/yqlib/operator_comments_test.go | 2 +- pkg/yqlib/operator_parent_test.go | 6 +++--- 5 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 pkg/yqlib/doc/headers/parent.md diff --git a/pkg/yqlib/doc/comment-operators.md b/pkg/yqlib/doc/comment-operators.md index 6086b20a..809ba5c4 100644 --- a/pkg/yqlib/doc/comment-operators.md +++ b/pkg/yqlib/doc/comment-operators.md @@ -139,7 +139,7 @@ will output welcome! ``` -## +## Head comment with document split Given a sample.yml file of: ```yaml # welcome! diff --git a/pkg/yqlib/doc/headers/parent.md b/pkg/yqlib/doc/headers/parent.md new file mode 100644 index 00000000..9e60cd82 --- /dev/null +++ b/pkg/yqlib/doc/headers/parent.md @@ -0,0 +1,3 @@ +# Parent + +Parent simply returns the parent nodes of the matching nodes. diff --git a/pkg/yqlib/doc/parent.md b/pkg/yqlib/doc/parent.md index 940c7581..30c78929 100644 --- a/pkg/yqlib/doc/parent.md +++ b/pkg/yqlib/doc/parent.md @@ -1,3 +1,6 @@ +# Parent + +Parent simply returns the parent nodes of the matching nodes. ## Simple example Given a sample.yml file of: @@ -14,13 +17,15 @@ will output nested: cat ``` -## Show parent +## Parent of nested matches Given a sample.yml file of: ```yaml a: fruit: apple + name: bob b: fruit: banana + name: sam ``` then ```bash @@ -29,6 +34,7 @@ yq eval '.. | select(. == "banana") | parent' sample.yml will output ```yaml fruit: banana +name: sam ``` ## No parent diff --git a/pkg/yqlib/operator_comments_test.go b/pkg/yqlib/operator_comments_test.go index bd724a8f..cc3ce4fe 100644 --- a/pkg/yqlib/operator_comments_test.go +++ b/pkg/yqlib/operator_comments_test.go @@ -113,7 +113,7 @@ var commentOperatorScenarios = []expressionScenario{ }, }, { - skipDoc: false, + description: "Head comment with document split", dontFormatInputForDoc: true, document: "# welcome!\n---\n# bob\na: cat # meow\n\n# have a great day", expression: `headComment`, diff --git a/pkg/yqlib/operator_parent_test.go b/pkg/yqlib/operator_parent_test.go index 680f4789..f4cbf236 100644 --- a/pkg/yqlib/operator_parent_test.go +++ b/pkg/yqlib/operator_parent_test.go @@ -14,11 +14,11 @@ var parentOperatorScenarios = []expressionScenario{ }, }, { - description: "Show parent", - document: `{a: {fruit: apple}, b: {fruit: banana}}`, + description: "Parent of nested matches", + document: `{a: {fruit: apple, name: bob}, b: {fruit: banana, name: sam}}`, expression: `.. | select(. == "banana") | parent`, expected: []string{ - "D0, P[b], (!!map)::{fruit: banana}\n", + "D0, P[b], (!!map)::{fruit: banana, name: sam}\n", }, }, {