etix/mirrorbits

Line-wrapping in YAML output makes life difficult

elboulangero opened this issue · 2 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. go-yaml/yaml@7649d45 for details)

I propose to disable line wrapping, without switching to yaml.v3, with this patch: #154

Alternatively, let's just bump the gopkg.in/yaml dependency to v3: #163