1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00
yq/pkg/yqlib/doc/Comment Operators.md
Mike Farah f7f8bed955 wip
2020-12-27 09:55:21 +11:00

1.5 KiB

Use these comment operators to set or retrieve comments.

Set line comment

Given a sample.yml file of:

a: cat
'': null

then

yq eval '.a lineComment="single"' sample.yml

will output

a: cat # single
'': null

Set head comment

Given a sample.yml file of:

a: cat
'': null

then

yq eval '. headComment="single"' sample.yml

will output

# single

a: cat
'': null

Set foot comment, using an expression

Given a sample.yml file of:

a: cat
'': null

then

yq eval '. footComment=.a' sample.yml

will output

a: cat
'': null

# cat

Remove comment

Given a sample.yml file of:

a: cat # comment
b: dog # leave this
'': null

then

yq eval '.a lineComment=""' sample.yml

will output

a: cat
b: dog # leave this
'': null

Remove all comments

Given a sample.yml file of:

a: cat # comment
'': null

then

yq eval '.. comments=""' sample.yml

will output

a: cat # comment
'': null

Get line comment

Given a sample.yml file of:

a: cat # meow
'': null

then

yq eval '.a | lineComment' sample.yml

will output

meow

Get head comment

Given a sample.yml file of:

a: cat # meow
'': null

then

yq eval '. | headComment' sample.yml

will output


Get foot comment

Given a sample.yml file of:

a: cat # meow
'': null

then

yq eval '. | footComment' sample.yml

will output