yq
yq copied to clipboard
Preserve formatting with in place writing
Describe the bug
yq w -1
command removes blank lines and changes spacing before comments.
Input Yaml Concise yaml document(s) (as simple as possible to show the bug) data1.yml:
# Log level for operator
logLevel: 3
# Annotations applied to operator deployment
annotations: {}
# Annotations passed to operator pod(s).
podAnnotations: {}
# Node labels for pod assignment
nodeSelector: # +doc-gen:break
beta.kubernetes.io/os: linux
beta.kubernetes.io/arch: amd64
Command The command you ran:
yq w -i test.yaml logLevel 4
Actual behavior
# Log level for operator
logLevel: 4
# Annotations applied to operator deployment
annotations: {}
# Annotations passed to operator pod(s).
podAnnotations: {}
# Node labels for pod assignment
nodeSelector: # +doc-gen:break
beta.kubernetes.io/os: linux
beta.kubernetes.io/arch: amd64
Expected behavior
# Log level for operator
logLevel: 4
# Annotations applied to operator deployment
annotations: {}
# Annotations passed to operator pod(s).
podAnnotations: {}
# Node labels for pod assignment
nodeSelector: # +doc-gen:break
beta.kubernetes.io/os: linux
beta.kubernetes.io/arch: amd64
Additional context Add any other context about the problem here.
$ yq --version
yq version 3.3.2
Yep - this is due to the underlying go-yaml parser, I see someone has already raised an issue there:
https://github.com/go-yaml/yaml/issues/627
Thanks for the confirmation. Something else is also broken between v3.3.0
(working) and v3.3.2
. I am running the following command:
yq r api/crds/installer.voyagermesh.com_voyageroperators.v1.yaml spec.versions[0].schema.openAPIV3Schema.properties.spec > /tmp/voyager-values.openapiv3_schema.yaml
You can see the files here: https://gist.github.com/tamalsaha/eeee8d9d2db6623bf1c77717ba3b2c2d
In v3.3.0
, the formatting of strings remain unchanged (newlines are preserved). In v3.3.2
, the newlines are gone.
Ah yeah I updated the go-yaml library in 3.3.1 which had a number of changes and fixes. That is an open issue against the lib (https://github.com/go-yaml/yaml/issues/627)
Looks like go-yaml decided to not fix the issue, rather just document it. :disappointed:
Would be helpful to preserve the original formatting!
It would also be nice to be able to preserve document markers (---). Seems like a great tool but unfortunately not being able to preserve virtually all the formatting is a dealbreaker for us.
Just wanted to second this, love the tool but also love our blank lines 😁
It also changes our yml files from 4 spaces indentation to 2 :(