Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ users)
## Pin

## List
* Add `license` as a possible field name in the columns argument [#6841 @raphael-proust]

## Show
* Improve performance of `opam show` by reading switch selection only once instead of once per package-version [#6818 @dra27]
Expand Down
2 changes: 2 additions & 0 deletions src/client/opamArg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,8 @@ let package_listing cli =
let columns =
mk_opt ~cli cli_original ["columns"] "COLUMNS" ~section
(Printf.sprintf "Select the columns to display among: %s.\n\
The special form $(b,<field>:) (field name followed by \
colon, e.g., $(b,license:)) selects an arbitraty field. \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
colon, e.g., $(b,license:)) selects an arbitraty field. \
colon, e.g., $(b,license:)) selects an arbitrary field. \

The default is $(b,name) when $(i,--short) is present \
and %s otherwise."
(OpamStd.List.concat_map ", " (fun (_,f) -> Printf.sprintf "$(b,%s)" f)
Expand Down
12 changes: 12 additions & 0 deletions src/client/opamListCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ type output_format =
| Field of string
| Raw_field of string
| Installed_version
| License
| Pinning_target
| Source_hash
| Raw
Expand All @@ -452,6 +453,7 @@ let disp_header = function
| Description -> "Description"
| Field s | Raw_field s -> String.capitalize_ascii s
| Installed_version -> "Installed"
| License -> "License"
| Pinning_target -> "Pin"
| Source_hash -> "Source hash"
| Raw -> "Metadata"
Expand All @@ -473,6 +475,7 @@ let field_names = [
Field "<field>", "<field>";
Raw_field "<field>:", "<field>:";
Installed_version, "installed-version";
License, "license";
Pinning_target, "pin";
Source_hash, "source-hash";
Raw, "opam-file";
Expand Down Expand Up @@ -624,6 +627,15 @@ let detail_printer ?prettify ?normalise ?(sort=false) installed st nv =
then s % [`bold;`yellow] else
s % [`magenta]
with Not_found -> "--" % [`cyan])
| License ->
(try
get_opam st nv |>
OpamFile.OPAM.to_list |>
OpamStd.List.assoc_opt String.equal "license" |>
function
| None -> "--" % [`cyan]
| Some f -> mini_field_printer f
with _ -> "--" % [`cyan])
| Pinning_target ->
if OpamPackage.Set.mem nv st.pinned then
let opam = get_opam st nv in
Expand Down
1 change: 1 addition & 0 deletions src/client/opamListCommand.mli
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type output_format =
| Field of string (** The value of the given opam-file field *)
| Raw_field of string (** The raw value of the given opam-file field *)
| Installed_version (** Installed version or "--" if none *)
| License (** License or "--" if not found *)
| Pinning_target (** Empty string if not pinned *)
| Source_hash (** The VC-reported ident of current version, for dev
packages. Empty if not available *)
Expand Down
21 changes: 21 additions & 0 deletions tests/reftests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,27 @@
%{targets}
(run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:list-coinstallable.test} %{read-lines:testing-env}))))

(rule
(alias reftest-list-format)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(action
(diff list-format.test list-format.out)))

(alias
(name reftest)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(deps (alias reftest-list-format)))

(rule
(targets list-format.out)
(deps root-N0REP0)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(package opam)
(action
(with-stdout-to
%{targets}
(run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:list-format.test} %{read-lines:testing-env}))))

(rule
(alias reftest-list-large-dependencies)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) )))
Expand Down
62 changes: 62 additions & 0 deletions tests/reftests/list-format.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
N0REP0
### : Dependencies on disjunction :
### <pkg:top.1>
opam-version: "2.0"
license: "MIT"
depends: [
"unrelated"
( "choice" | "other-choice" { >= "2" & <= "4" } | "other-choice" )
]
### <pkg:unrelated.1>
opam-version: "2.0"
license: "ISC"
### <pkg:choice.1>
opam-version: "2.0"
license: "ISC"
### <pkg:other-choice.1>
opam-version: "2.0"
depends: "shouldnt"
### <pkg:shouldnt.1>
opam-version: "2.0"
### <pkg:other-choice.2>
opam-version: "2.0"
license: "ISC"
### <pkg:other-choice.3>
opam-version: "2.0"
license: "ISC"
### <pkg:other-choice.4>
opam-version: "2.0"
license: "ISC"
### <pkg:other-choice.1>
opam-version: "2.0"
depends: "should"
### <pkg:should.1>
opam-version: "2.0"
license: "AGPL"
### opam list --all
# Packages matching: any
# Name # Installed # Synopsis
choice --
other-choice --
should --
shouldnt --
top --
unrelated --
### opam list --all --columns=name,installed-version,synopsis,license
# Packages matching: any
# Name # Installed # Synopsis # License
choice -- "ISC"
other-choice -- "ISC"
should -- "AGPL"
shouldnt -- --
top -- "MIT"
unrelated -- "ISC"
### opam list --all --columns=name,synopsis:,license:
# Packages matching: any
# Name # Installed # Synopsis # License
choice -- "ISC"
other-choice -- "ISC"
should -- "AGPL"
shouldnt -- --
top -- "MIT"
unrelated -- "ISC"
Loading