-
Notifications
You must be signed in to change notification settings - Fork 93
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
Line-wrapping in YAML output makes life difficult #153
Comments
elboulangero
added a commit
to elboulangero/mirrorbits
that referenced
this issue
Nov 8, 2023
elboulangero
added a commit
to elboulangero/mirrorbits
that referenced
this issue
Nov 8, 2023
Line wrapping after 80 characters was the default in yaml.v2. No line wrapping is the default for yaml.v3. The helper FutureLineWrap() is meant to help users do the transition to the new behavior. For mirrorbits, line wrapping manifests itselfs for the `show` and `edit` commands. It's an issue, in the sense that it makes it difficult for scripts to interact with those commands (as long values might spread on several lines, so a simple grep won't do). Hence this commit disables line wrapping. Closes: etix#153
I propose to disable line wrapping, without switching to yaml.v3, with this patch: #154 |
elboulangero
added a commit
to elboulangero/mirrorbits
that referenced
this issue
Feb 2, 2024
The main reason to switch (apart from keeping dependencies up-to-date) is the default behaviour for line wrapping. In yaml.v2, the default was line wrapping after 80 characters. In yaml.v3, no line wrapping by default. For mirrorbits, line wrapping manifests itself in the `show` and `edit` commands. It's an issue, in the sense that it makes it difficult for scripts to interact with those commands, since long values might spread over several lines. For example, parsing the output of `mirrorbits show` with `grep` is error prone because of line wrapping. This commit bumps the build depencency gopkg.in/yaml from v2 to v3, thus disabling line wrapping in yaml output. Closes: etix#153
elboulangero
changed the title
Wrapping long lines in YAML output makes life difficult
Line-wrapping in YAML output makes life difficult
Feb 2, 2024
Alternatively, let's just bump the gopkg.in/yaml dependency to v3: #163 |
jbkempf
pushed a commit
that referenced
this issue
Feb 3, 2024
The main reason to switch (apart from keeping dependencies up-to-date) is the default behaviour for line wrapping. In yaml.v2, the default was line wrapping after 80 characters. In yaml.v3, no line wrapping by default. For mirrorbits, line wrapping manifests itself in the `show` and `edit` commands. It's an issue, in the sense that it makes it difficult for scripts to interact with those commands, since long values might spread over several lines. For example, parsing the output of `mirrorbits show` with `grep` is error prone because of line wrapping. This commit bumps the build depencency gopkg.in/yaml from v2 to v3, thus disabling line wrapping in yaml output. Closes: #153
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
The yaml library, and more precisely
yaml.Marshal
, wraps long lines after 80 characters by default. It is not configurable. It's an awkward default, and it's been fixed in the yaml.v3 library (where the default is no line wrapping). But in yaml.v2, for backward compat, they couldn't change it, so line wrapping is on.In mirrorbits, it manifests in the
show
andedit
commands. For example:Above, we can see that
SponsorName
spawns on two lines. Same behavior withmirrorbits edit
.It is a problem for scripts. For example, a script that parses the output of
mirrorbits show
, and based on a simple grep, will fail to get the second line.Part of our Ansible playbook, we also edit the mirrors programmatically, and the line-wrapping makes it difficult.
Solutions
Solution is to disable line wrapping, which can be done in two ways:
yaml.v3
(as it doesn't wrap by default)yaml.FutureLineWrap()
to disable line wrapping (cf. go-yaml/yaml@7649d45 for details)The text was updated successfully, but these errors were encountered: