ocaml / opam

opam is a source-based package manager. It supports multiple simultaneous compiler installations, flexible package constraints, and a Git-friendly development workflow.
https://opam.ocaml.org
Other
1.24k stars 358 forks source link

opam show could be more consistent with newlines #3415

Open avsm opened 6 years ago

avsm commented 6 years ago

This is frustratingly hard to parse from a shell script :)

$ opam show -f depends: sexplib0 
"ocaml" {>= "4.04.1"} "jbuilder" {build & >= "1.0+beta18.1"}
$ opam show -f depends: mirage 
"ocaml" {>= "4.04.2"}
"ocamlbuild"
"ocamlfind"
"jbuilder" {build & >= "1.0+beta10"}
"ipaddr" {>= "2.6.0"}
"functoria" {>= "2.2.0"}
"bos"
"astring"
"logs"
"mirage-runtime" {>= "3.0.0"}

If opam show would just make every list entry into a newline, it would be so much simpler to parse with line-oriented tools in a shell. Using --normalise adds brackets and makes it harder to parse.

avsm commented 6 years ago

I'm also noticing that the output of opam show --normalise can't always be parsed by OpamParser.value_of_string. If there is an empty string, a Parsing_error is raised.

dbuenzli commented 6 years ago

Also would it be possible to only report what is in the file when this is performed on an opam file; it seems that opam will invent things in some cases (here on an opam file that has no version: field):

> opam show ./opam -f version:,homepage: --normalise --no-lint
version:  "~dev"
homepage: ["bla" "bli" "blo"]
rjbou commented 6 years ago

It have its origins in opam-file-format. If we change the printer at this stage, it will change opam printing for all tools, even camelus. Meanwhile, it is possible to pin for the CI a version of opam-file-format that "disable" that formatting.