Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom indent for lists #1309

Open
kaovilai opened this issue Aug 18, 2022 · 4 comments
Open

Custom indent for lists #1309

kaovilai opened this issue Aug 18, 2022 · 4 comments

Comments

@kaovilai
Copy link
Contributor

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:

  • how to questions should be posted in the discussion board and not raised as an issue.
  • V3 will no longer have any enhancements.

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.
openshift/oadp-operator#796

@mikefarah
Copy link
Owner

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

@zmedico
Copy link

zmedico commented May 22, 2024

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

@kaovilai
Copy link
Contributor Author

that is a cool tip. Thanks!

@jedvardsson
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants