Given /tmp/yam:
top:
yam:
notyam: nope
Actual result:
# cat <<EOF | yq w /tmp/yam top.ugh -
# pipe heredoc> |
# pipe heredoc> ugh
# pipe heredoc> EOF
top:
yam:
notyam: nope
ugh: '-'
# yq w /tmp/yam top.ugh "$(echo -e '|\n wat')"
top:
yam:
notyam: nope
ugh: |-
|
wat
# yq w /tmp/yam top.ugh "$(echo -e '\nwat')"
top:
yam:
notyam: nope
ugh: |2-
wat
# yq w /tmp/yam top "$(echo -e 'ugh: |\n wat')"
top: |-
ugh: |
wat
Expected result:
top:
yam:
notyam: nope
ugh: |
wat
Ideally, there'd be a flag to treat stdin as you're value in write mode instead of source file content or a [<symbol>] "filter" to denote a multiline value to gain representation as a scalar in w mode(s).
As a workaround, writing out a separate file with the preceding/parent mappings and then using the m (merge) mode works:
# cat <<EOF > /tmp/ugh && yq m /tmp/yam /tmp/ugh
# top:
# ugh: |
# wat
# EOF
top:
ugh: |
wat
yam:
notyam: nope
Am I.. doing it wrong?
No you're not doing it wrong - yq doesn't yet support this ;(
Seems related to https://github.com/mikefarah/yq/issues/107
Ah ok. I was trying to sort this out all day. Funnily what i got from
yq w test.yaml objects[0].tls.certificate -- "$(cat cert.pem)"
was
!! binary |
[[the base64 encoded string of the value I wanted to add]]
Would be awesome if this feature was added. Is this a feature being planned?
FWIW: I ended up going with https://www.npmjs.com/package/yaml-cli for my use case (consuming yaml and producing a json packer) wherein there's a ton of heredoc-style shell scripts/yaml scalars. I'd still love to see this feature in yq tho.
Just released a new version of yaml that fixes this - it's a pretty significant update so it's still in beta: https://github.com/mikefarah/yq/releases/tag/3.0.0-beta
Most helpful comment
Just released a new version of yaml that fixes this - it's a pretty significant update so it's still in beta: https://github.com/mikefarah/yq/releases/tag/3.0.0-beta