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

Line-wrapping in YAML output makes life difficult #153

Closed
elboulangero opened this issue Nov 8, 2023 · 2 comments · Fixed by #163
Closed

Line-wrapping in YAML output makes life difficult #153

elboulangero opened this issue Nov 8, 2023 · 2 comments · Fixed by #163

Comments

@elboulangero
Copy link
Contributor

elboulangero commented Nov 8, 2023

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 and edit commands. For example:

$ mirrorbits show kali.cs.nycu.edu.tw
[...]
FtpURL: ""
SponsorName: Computer Center, Department of Computer Science, National Yang Ming Chiao
  Tung University
SponsorURL: https://it.cs.nycu.edu.tw
[...[

Above, we can see that SponsorName spawns on two lines. Same behavior with mirrorbits 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:

  • switch to the library yaml.v3 (as it doesn't wrap by default)
  • use yaml.FutureLineWrap() to disable line wrapping (cf. go-yaml/yaml@7649d45 for details)
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
@elboulangero
Copy link
Contributor Author

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 elboulangero changed the title Wrapping long lines in YAML output makes life difficult Line-wrapping in YAML output makes life difficult Feb 2, 2024
@elboulangero
Copy link
Contributor Author

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
Labels
None yet
Projects
None yet
1 participant