etix / mirrorbits

Mirrorbits is a geographical download redirector written in Go for distributing files efficiently across a set of mirrors.
MIT License
503 stars 91 forks source link

Line-wrapping in YAML output makes life difficult #153

Closed elboulangero closed 7 months ago

elboulangero commented 10 months ago

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:

elboulangero commented 10 months ago

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

elboulangero commented 8 months ago

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