mirrorbits icon indicating copy to clipboard operation
mirrorbits copied to clipboard

Wrapping long lines in YAML output makes life difficult

Open elboulangero opened this issue 1 year ago • 1 comments

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. https://github.com/go-yaml/yaml/commit/7649d4548cb53a614db133b2a8ac1f31859dda8c for details)

elboulangero avatar Nov 08 '23 08:11 elboulangero

I propose to disable line wrapping, without switching to yaml.v3, with this patch: https://github.com/etix/mirrorbits/pull/154

elboulangero avatar Nov 08 '23 08:11 elboulangero

Alternatively, let's just bump the gopkg.in/yaml dependency to v3: https://github.com/etix/mirrorbits/pull/163

elboulangero avatar Feb 02 '24 14:02 elboulangero