mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Added another comment test
This commit is contained in:
parent
a4b60039ca
commit
be304a1102
@ -1,12 +1,5 @@
|
|||||||
# --------------------------------------------------
|
volumes:
|
||||||
# It's a test with comment
|
beehive-conf:
|
||||||
# --------------------------------------------------
|
driver: local
|
||||||
test:
|
services:
|
||||||
- name: a
|
- beehive
|
||||||
- name: b
|
|
||||||
- name: c
|
|
||||||
groups:
|
|
||||||
- name: a
|
|
||||||
- name: b
|
|
||||||
- name: c
|
|
||||||
- name: c
|
|
@ -17,6 +17,8 @@ Note that versions prior to 4.18 require the 'eval/e' command to be specified.&#
|
|||||||
{% endhint %}
|
{% endhint %}
|
||||||
|
|
||||||
## Set line comment
|
## Set line comment
|
||||||
|
Set the comment on the key node for more reliability (see below).
|
||||||
|
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
a: cat
|
a: cat
|
||||||
@ -30,6 +32,24 @@ will output
|
|||||||
a: cat # single
|
a: cat # single
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Set line comment of a maps/arrays
|
||||||
|
For maps and arrays, you need to set the line comment on the _key_ node. This will also work for scalars.
|
||||||
|
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a:
|
||||||
|
b: things
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '(.a | key) line_comment="single"' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
a: # single
|
||||||
|
b: things
|
||||||
|
```
|
||||||
|
|
||||||
## Use update assign to perform relative updates
|
## Use update assign to perform relative updates
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -7,12 +7,22 @@ import (
|
|||||||
var commentOperatorScenarios = []expressionScenario{
|
var commentOperatorScenarios = []expressionScenario{
|
||||||
{
|
{
|
||||||
description: "Set line comment",
|
description: "Set line comment",
|
||||||
|
subdescription: "Set the comment on the key node for more reliability (see below).",
|
||||||
document: `a: cat`,
|
document: `a: cat`,
|
||||||
expression: `.a line_comment="single"`,
|
expression: `.a line_comment="single"`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (doc)::a: cat # single\n",
|
"D0, P[], (doc)::a: cat # single\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Set line comment of a maps/arrays",
|
||||||
|
subdescription: "For maps and arrays, you need to set the line comment on the _key_ node. This will also work for scalars.",
|
||||||
|
document: "a:\n b: things",
|
||||||
|
expression: `(.a | key) line_comment="single"`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (doc)::a: # single\n b: things\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
document: "a: cat\nb: dog",
|
document: "a: cat\nb: dog",
|
||||||
|
Loading…
Reference in New Issue
Block a user