Skip to content

Commit

Permalink
Another comment example
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Feb 9, 2024
1 parent 2871fa0 commit 1d06d8b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/yqlib/doc/usage/formatting-expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

7 changes: 7 additions & 0 deletions pkg/yqlib/formatting_expressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down

0 comments on commit 1d06d8b

Please sign in to comment.