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

--yaml-output breaks yaml file format #93

Closed
jean-christophe-manciot opened this issue Apr 22, 2020 · 7 comments
Closed

--yaml-output breaks yaml file format #93

jean-christophe-manciot opened this issue Apr 22, 2020 · 7 comments

Comments

@jean-christophe-manciot

yq: 2.10.0
With the following input yaml file yaml_list_dict.yml:

---
yaml_struct:
  - key_1: '$.*?/|\^(){}+@[]&_-'
    key_2:
      - '$.*?/|\^(){}+@[]&_-'
      - "{\_}"
      - value23
    key_3: value31
    key_4:
      - value41
      - value42
    key_5: value51
  - key_1_: value12
    _key_2:
      - value24
      - value25
    _key__3: '$.*?/|\^(){}+@[]&_-'
...

The following command breaks the original format:

yq --sort-keys --yaml-output . ./yaml_list_dict.yml
yaml_struct:
  - key_1: $.*?/|\^(){}+@[]&_-
    key_2:
      - $.*?/|\^(){}+@[]&_-
      - '{ }'
      - value23
    key_3: value31
    key_4:
      - value41
      - value42
    key_5: value51
  - _key_2:
      - value24
      - value25
    _key__3: $.*?/|\^(){}+@[]&_-
    key_1_: value12

The original ---`` and ...``` have been removed.
Am I missing something?

@kislyuk
Copy link
Owner

kislyuk commented Apr 22, 2020

You are looking to preserve explicit start and explicit end YAML document markers. This is not yet supported by yq. I will add this as an option.

@dosmanak
Copy link

Hello. I digged in code to found it is possible to add argument --explicit-start to yq, it is not showed in help. Why do you suppress it?

@ssbarnea
Copy link

ssbarnea commented Jul 3, 2023

If the feature is available, I am so quite curious why it is hidden.

@jean-christophe-manciot
Copy link
Author

The new options are --explicit-start and --explicit-end.

@kislyuk
Copy link
Owner

kislyuk commented Jul 4, 2023

OK, I documented the new options in the readme and online help.

@dosmanak
Copy link

dosmanak commented Jul 5, 2023

OK, I documented the new options in the readme and online help.

Thanks, but why do you supress it in the --help?

yq/yq/parser.py

Line 102 in 5d0be22

parser.add_argument("--explicit-start", action="store_true", help=argparse.SUPPRESS)

@kislyuk
Copy link
Owner

kislyuk commented Jul 5, 2023

It's suppressed by default because the help strings are used for 3 different utilities (yq, xq and tomlq) and un-suppressed for yq.

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

No branches or pull requests

4 participants