kislyuk / yq

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
https://kislyuk.github.io/yq/
Apache License 2.0
2.57k stars 82 forks source link

--yaml-output breaks yaml file format #93

Closed jean-christophe-manciot closed 4 years ago

jean-christophe-manciot commented 4 years ago

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 commented 4 years ago

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 commented 2 years ago

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 commented 1 year ago

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

jean-christophe-manciot commented 1 year ago

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

kislyuk commented 1 year ago

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

dosmanak commented 1 year ago

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

Thanks, but why do you supress it in the --help? https://github.com/kislyuk/yq/blob/5d0be22c271bd8dbf80b7509cf64240d0f2ca555/yq/parser.py#L102

kislyuk commented 1 year ago

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