Skip to content

Commit

Permalink
Add a new --latests-only option to opam list & opam admin list to onl…
Browse files Browse the repository at this point in the history
…y work on the set of latest packages
  • Loading branch information
kit-ty-kate committed Dec 2, 2022
1 parent fb9921e commit eb5ecc4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/client/opamArg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1594,16 +1594,21 @@ let package_selection cli =
"Only includes packages which have the given tag set"
Arg.string
in
let latests_only =
mk_flag ~cli (cli_from cli2_2) ["latests-only"] ~section
"List only the latest version of each package."
in
let filter
depends_on required_by conflicts_with coinstallable_with resolve
recursive depopts nobuild post dev doc_flag test dev_setup field_match
has_flag has_tag
has_flag has_tag latests_only
=
let dependency_toggles = {
OpamListCommand.
recursive; depopts; build = not nobuild; post; test; dev_setup;
doc = doc_flag; dev
} in
(if latests_only then [OpamListCommand.Latests_only] else []) @
List.map (fun flag -> OpamListCommand.Flag flag) has_flag @
List.map (fun tag -> OpamListCommand.Tag tag) has_tag @
List.map (fun (field,patt) ->
Expand Down Expand Up @@ -1632,7 +1637,7 @@ let package_selection cli =
depends_on $ required_by $ conflicts_with $ coinstallable_with $
resolve $ recursive $ depopts $ nobuild $ post cli $ dev cli $
doc_flag cli $ test cli $ dev_setup cli $ field_match $ has_flag $
has_tag)
has_tag $ latests_only)

let package_listing_section = "OUTPUT FORMAT OPTIONS"

Expand Down
7 changes: 7 additions & 0 deletions src/client/opamListCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type selector =
| Available
| Installable
| Pinned
| Latests_only
| Depends_on of dependency_toggles * atom list
| Required_by of dependency_toggles * atom list
| Conflicts_with of package list
Expand All @@ -86,6 +87,7 @@ let string_of_selector =
| Available -> "available" % `cyan
| Installable -> "installable" % `cyan
| Pinned -> "pinned" % `cyan
| Latests_only -> "latest-only" % `cyan
| Depends_on (tog,atoms) ->
Printf.sprintf "%s(%s)"
((if tog.recursive then "rec-depends-on" else "depends-on") % `blue)
Expand Down Expand Up @@ -222,6 +224,11 @@ let apply_selector ~base st = function
(OpamSwitchState.universe st ~requested:OpamPackage.Set.empty Query)
base
| Pinned -> OpamPinned.packages st
| Latests_only ->
OpamPackage.to_map base |>
OpamPackage.Name.Map.map (fun vset ->
OpamPackage.Version.Set.singleton (OpamPackage.Version.Set.max_elt vset)) |>
OpamPackage.of_map
| (Required_by ({recursive=true; _} as tog, atoms)
| Depends_on ({recursive=true; _} as tog, atoms)) as direction ->
let deps_fun = match direction with
Expand Down
1 change: 1 addition & 0 deletions src/client/opamListCommand.mli
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type selector =
| Available
| Installable
| Pinned
| Latests_only
| Depends_on of dependency_toggles * atom list
| Required_by of dependency_toggles * atom list
| Conflicts_with of package list
Expand Down

0 comments on commit eb5ecc4

Please sign in to comment.