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.62k stars 84 forks source link

Yaml document have to start from three dashes #61

Closed freeseacher closed 5 years ago

freeseacher commented 5 years ago

https://yaml.org/spec/1.2/spec.html

kislyuk commented 5 years ago

This is not the case in practice nor in the spec; section 9.1.3 describes "bare documents" which do not contain the separator.

Is there a specific reason why your use case requires this? Most YAML users don't use the separator, and it's important to match the expectations of most users. It may be possible to add this behavior as optional if there's a strong argument for it.

freeseacher commented 5 years ago

My use case is pretty simple. i want to deep sort kubernetes manifests. They tend to be unsorted and searching for specific option is a disaster. I store each manifest in one file. There are lots of files. Also i use yamllint. I have to use it because of internal policy. Yamllint out of scope of my configuration and requires explicit doc start.

There are also troubles with indentation in lists. That require to be two spaces. i can't find a good tool to automaticaly fix my yamls according to yamlllint :(

freeseacher commented 5 years ago

i am talking about https://github.com/kislyuk/yq/issues/52 specifically

jayvdb commented 5 years ago

i can't find a good tool to automaticaly fix my yamls according to yamlllint :(

c.f. https://github.com/adrienverge/yamllint/issues/62 formatting is out of scope.

yaccob commented 5 years ago

This is not the case in practice nor in the spec; section 9.1.3 describes "bare documents" which do not contain the separator.

Is there a specific reason why your use case requires this? Most YAML users don't use the separator, and it's important to match the expectations of most users. It may be possible to add this behavior as optional if there's a strong argument for it.

I'm also quite interested in getting support for the --- separator (optionally for not breaking any existing clients). A big advantage of using the separator is that you can concatenate multiple yq outputs to a valid multi-document yaml file without additional programming effort.

jayvdb commented 5 years ago

ping @freeseacher , your PR has conflicts that need to be resolved.

kislyuk commented 5 years ago

@yaccob I appreciate the concern about this, but you can already do this using existing yq functionality.

>cat f.yaml
foo: bar
>yq . f.yaml f.yaml
{
  "foo": "bar"
}
{
  "foo": "bar"
}
>yq -y . f.yaml f.yaml
foo: bar
---
foo: bar
kislyuk commented 5 years ago

At this point I do not judge this feature to be required in yq. I do agree that configurable indentation and/or fixing the indentation defaults in PyYAML would be nice, which is tracked by #52.