mikefarah / yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
https://mikefarah.gitbook.io/yq/
MIT License
11.92k stars 585 forks source link

Custom indent for lists #1309

Open kaovilai opened 2 years ago

kaovilai commented 2 years ago

Please describe your feature request. A clear and concise description of what the request is and what it would solve. Eg. I wish I could use yq to [...] have custom indent for list/arrays.

related to #194

Note:

Describe the solution you'd like If we have data1.yml like: (please keep to around 10 lines )

country: Australia
  province: space
citizen:
  - 1
  - 2

And we run a command:

yq --no-list-indent '.' data1.yml

it could output

country: Australia
  province: space
citizen:
- 1
- 2

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

yq --list-indent 0 '.' data1.yml

Additional context Add any other context or screenshots about the feature request here. Would like to avoid indent changes to original file. https://github.com/openshift/oadp-operator/pull/796

mikefarah commented 2 years ago

Unfortunately this parameter is not exposed by the underlying yaml parser (go-yaml) - until it is not much can be done.

zmedico commented 3 months ago

As a workaround for this issue I pipe the yaml through a yamlfmt command like yamlfmt -in -formatter indentless_arrays=true.

kaovilai commented 3 months ago

that is a cool tip. Thanks!

jedvardsson commented 1 month ago

The kubernetes team have this problem too. They have forked go-yaml and applied a fix: https://github.com/kubernetes-sigs/yaml/blob/master/goyaml.v3/patch.go