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

Indentation with --indent/-I does not work as expected #825

Open
tchupp opened this issue May 20, 2021 · 4 comments
Open

Indentation with --indent/-I does not work as expected #825

tchupp opened this issue May 20, 2021 · 4 comments
Labels

Comments

@tchupp
Copy link

tchupp commented May 20, 2021

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.

@mikefarah
Copy link
Owner

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:

@tchupp
Copy link
Author

tchupp commented May 21, 2021

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?

@rheaton
Copy link

rheaton commented Jul 1, 2021

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

@matheusmaais
Copy link

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

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

No branches or pull requests

4 participants