File tree Expand file tree Collapse file tree 3 files changed +38
-15
lines changed Expand file tree Collapse file tree 3 files changed +38
-15
lines changed Original file line number Diff line number Diff line change 1
- # --------------------------------------------------
2
- # It's a test with comment
3
- # --------------------------------------------------
4
- test :
5
- - name : a
6
- - name : b
7
- - name : c
8
- groups :
9
- - name : a
10
- - name : b
11
- - name : c
12
- - name : c
1
+ volumes :
2
+ beehive-conf :
3
+ driver : local
4
+ services :
5
+ - beehive
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ Note that versions prior to 4.18 require the 'eval/e' command to be specified.&#
17
17
{% endhint %}
18
18
19
19
## Set line comment
20
+ Set the comment on the key node for more reliability (see below).
21
+
20
22
Given a sample.yml file of:
21
23
``` yaml
22
24
a : cat
@@ -30,6 +32,24 @@ will output
30
32
a : cat # single
31
33
` ` `
32
34
35
+ ## Set line comment of a maps/arrays
36
+ For maps and arrays, you need to set the line comment on the _key_ node. This will also work for scalars.
37
+
38
+ Given a sample.yml file of:
39
+ ` ` ` yaml
40
+ a :
41
+ b : things
42
+ ` ` `
43
+ then
44
+ ` ` ` bash
45
+ yq '(.a | key) line_comment="single"' sample.yml
46
+ ```
47
+ will output
48
+ ``` yaml
49
+ a : # single
50
+ b : things
51
+ ` ` `
52
+
33
53
## Use update assign to perform relative updates
34
54
Given a sample.yml file of:
35
55
` ` ` yaml
Original file line number Diff line number Diff line change @@ -6,13 +6,23 @@ import (
6
6
7
7
var commentOperatorScenarios = []expressionScenario {
8
8
{
9
- description : "Set line comment" ,
10
- document : `a: cat` ,
11
- expression : `.a line_comment="single"` ,
9
+ description : "Set line comment" ,
10
+ subdescription : "Set the comment on the key node for more reliability (see below)." ,
11
+ document : `a: cat` ,
12
+ expression : `.a line_comment="single"` ,
12
13
expected : []string {
13
14
"D0, P[], (doc)::a: cat # single\n " ,
14
15
},
15
16
},
17
+ {
18
+ description : "Set line comment of a maps/arrays" ,
19
+ subdescription : "For maps and arrays, you need to set the line comment on the _key_ node. This will also work for scalars." ,
20
+ document : "a:\n b: things" ,
21
+ expression : `(.a | key) line_comment="single"` ,
22
+ expected : []string {
23
+ "D0, P[], (doc)::a: # single\n b: things\n " ,
24
+ },
25
+ },
16
26
{
17
27
skipDoc : true ,
18
28
document : "a: cat\n b: dog" ,
You can’t perform that action at this time.
0 commit comments