From 1d06d8b482802caafeec9d3b470483c15f3b42de Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Fri, 9 Feb 2024 13:58:59 +1100 Subject: [PATCH] Another comment example --- pkg/yqlib/doc/usage/formatting-expressions.md | 28 +++++++++++++++++++ pkg/yqlib/formatting_expressions_test.go | 7 +++++ 2 files changed, 35 insertions(+) diff --git a/pkg/yqlib/doc/usage/formatting-expressions.md b/pkg/yqlib/doc/usage/formatting-expressions.md index 59503dd19c4..51e24117379 100644 --- a/pkg/yqlib/doc/usage/formatting-expressions.md +++ b/pkg/yqlib/doc/usage/formatting-expressions.md @@ -31,3 +31,31 @@ a: c: frog ``` +## Commenting out yq expressions +Note that `c` is no longer set to 'frog'. + +Given a sample.yaml file of: +```yaml +a: + b: old +``` +And an 'update.yq' expression file of: +```bash +# This is a yq expression that updates the map +# for several great reasons outlined here. + +.a.b = "new" # line comment here +# | .a.c = "frog" + +# Now good things will happen. +``` +then +```bash +yq --from-file update.yq sample.yml +``` +will output +```yaml +a: + b: new +``` + diff --git a/pkg/yqlib/formatting_expressions_test.go b/pkg/yqlib/formatting_expressions_test.go index 65ed3e10ad0..17f8fbdc692 100644 --- a/pkg/yqlib/formatting_expressions_test.go +++ b/pkg/yqlib/formatting_expressions_test.go @@ -15,6 +15,13 @@ var formattingExpressionScenarios = []formatScenario{ expression: "\n# This is a yq expression that updates the map\n# for several great reasons outlined here.\n\n.a.b = \"new\" # line comment here\n| .a.c = \"frog\"\n\n# Now good things will happen.\n", expected: "a:\n b: new\n c: frog\n", }, + { + description: "Commenting out yq expressions", + subdescription: "Note that `c` is no longer set to 'frog'.", + input: "a:\n b: old", + expression: "\n# This is a yq expression that updates the map\n# for several great reasons outlined here.\n\n.a.b = \"new\" # line comment here\n# | .a.c = \"frog\"\n\n# Now good things will happen.\n", + expected: "a:\n b: new\n", + }, } func documentExpressionScenario(_ *testing.T, w *bufio.Writer, i interface{}) {