Use these comment operators to set or retrieve comments.
Given a sample.yml file of:
a: cat
then
yq eval '.a lineComment="single"' sample.yml
will output
a: cat # single
Given a sample.yml file of:
a: catb: dog
then
yq eval '.. lineComment |= .' sample.yml
will output
a: cat # catb: dog # dog
Given a sample.yml file of:
a: cat
then
yq eval '. headComment="single"' sample.yml
will output
# single​a: cat
Given a sample.yml file of:
a: cat
then
yq eval '. footComment=.a' sample.yml
will output
a: cat​# cat
Given a sample.yml file of:
a: cat # commentb: dog # leave this
then
yq eval '.a lineComment=""' sample.yml
will output
a: catb: dog # leave this
Note the use of ...
to ensure key nodes are included.
Given a sample.yml file of:
a: cat # comment# greatb: # key comment
then
yq eval '... comments=""' sample.yml
will output
a: catb:
Given a sample.yml file of:
a: cat # meow
then
yq eval '.a | lineComment' sample.yml
will output
meow
Given a sample.yml file of:
a: cat # meow
then
yq eval '. | headComment' sample.yml
will output
​
Given a sample.yml file of:
a: cat # meow
then
yq eval '. | footComment' sample.yml
will output
​