yq
yq copied to clipboard
Pretty print just fixes indentation and doesn't convert/update any quoting style or collapse multiline strings
Please describe your feature request. Limit pretty-print functionality to just fix indentation, i.e. don't convert any quoting style and don't collapse multiline strings.
Current implementation will fix indentations and collapse multiline text.
Describe the solution you'd like
If we have some.yml like:
country: Australia
cities:
- Sydney
- Batemans Bay
description: |
Is a pretty country
with lots of animals
of different kinds.
And we run a command:
yq --prettyPrint --prettyJustIndent --inplace some.yml
it could output
country: Australia
cities:
- Sydney
- Batemans Bay
description: |
Is a pretty country
with lots of animals
of different kinds.
I just found out that there is another similar "pretty" print command: yq -I2 some.yml.
But despite the absence of any pretty print command line argument, this command actually collapses multiline strings too.
Yep that's the right way to do it.
Regarding the multiline string issue - it's actually a problem with the underlying yaml parser lib (https://github.com/go-yaml/yaml/tree/v3) which has issues raised it already (https://github.com/go-yaml/yaml/issues/166, https://github.com/go-yaml/yaml/issues/827)
The good news is despite being formatted differently, the actual value is still the same from a yaml perspective.
But yeah - annoying.
On this, is there any way to pretty print without indenting list items? I was under the impression from this comment that we could use -I4 to indent, whereas with the default of -I2 list items wouldn't be indented:
https://github.com/mikefarah/yq/issues/25#issuecomment-583188304
The indentation is entirely controlled by the underlying parser, I just give it a number and it does what it does :/
I'm not aware of a way to configure it to that granularity.