yq
yq copied to clipboard
Indentation with `--indent/-I` does not work as expected
Describe the bug
There is an inconsistency between the actual behavior of --indent/-I and the behavior described in this doc: https://mikefarah.gitbook.io/yq/usage/output-format#indent
I will provide several example commands, but the expected behavior is also in the docs I linked.
The version of yq: tried with v4.6.1 and v4.9.1 Operating system: mac Installed via: homebrew
Input Yaml Concise yaml document(s) (as simple as possible to show the bug, please keep it to 10 lines or less) sample.yml:
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
-I0
Command
yq e -I0 '.' sample.yaml
Actual behavior
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
Expected behavior Expected to default to 2.
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
-I1
Command
yq e -I1 '.' sample.yaml
Actual behavior
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
Expected behavior Expected to output with 1 indent, lists at the same level as the key.
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
-I2
Command
yq e -I2 '.' sample.yaml
Actual behavior
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
Expected behavior Expected to output with 2 indents, lists at the same level as the key.
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
-I3
Command
yq e -I3 '.' sample.yaml
Actual behavior
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
Expected behavior Expected to output with 3 indents, lists at the same level as the key.
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
-I4
Command
yq e -I3 '.' sample.yaml
Actual behavior
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
Expected behavior Expected to output with 4 indents, list indented 4 from the key.
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
Please let me know if more detail is required! Thank you.
Thanks @tchupp - the indentation is controlled by the underlying go-yaml parser (and has gone through a number of iterations). There are a couple of issues already raised in that project that I think relate to your bug:
- https://github.com/go-yaml/yaml/issues/720
- https://github.com/go-yaml/yaml/issues/501
I had a feeling it might have been caused by go-yaml’s behavior. Is there a version of yq where this behavior is preserved?
Hi! I'm seeing this list indenting even with -I2 which is contrary to the docs here: https://mikefarah.gitbook.io/yq/usage/output-format#indent
Hey guys, I'm trying to use Yq to replace some values on kubernetes manifest, and I noticed that yq it's not preserving spaces as described on issue description. Do we have any updates about this issue? I use macOS as well and it happens even if I'm not replacing the list itself.. any modified field changes the identation