Skip to content

Commit

Permalink
switch: 'opam switch list-available' will not display compilers flagg…
Browse files Browse the repository at this point in the history
…ed with 'avoid-version/deprecated' unless '--all' is given
  • Loading branch information
kit-ty-kate committed Aug 13, 2024
1 parent 266ea6e commit 3f40f9e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ users)
## Switch
* ◈ Add `opam switch import --deps-only` option to install only dependencies of root package at import [#5388 @rjbou - fix #5200]
* [BUG] Make accepted `--repos` URLs on creation consistent with `opam repository` [#6091 @Keryan-dev - fix #4673]
* ◈ opam switch list-available will not display compilers flagged with avoid-version/deprecated unless --all is given [#6098 @kit-ty-kate - fix #6089]

## Config

Expand Down
31 changes: 27 additions & 4 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2807,6 +2807,12 @@ let switch cli =
right away: wait for the next $(i,install), $(i,upgrade) or similar \
command."
in
let all =
mk_flag ~cli (cli_from cli2_3) ["all"]
"Only for $(i,list-available): show all available compilers, \
regardless of whether they are flagged with $(i,avoid-version) \
or $(i,deprecated)."
in
(* Deprecated options *)
let d_alias_of =
mk_opt ~cli (cli_between cli2_0 cli2_1)
Expand All @@ -2818,7 +2824,7 @@ let switch cli =
let switch
global_options build_options command print_short
no_switch packages formula empty descr full freeze no_install deps_only repos
force no_action
force no_action all
d_alias_of d_no_autoinstall params () =
if d_alias_of <> None then
OpamConsole.warning
Expand All @@ -2828,6 +2834,9 @@ let switch cli =
if d_no_autoinstall then
OpamConsole.warning "Option %s is deprecated, ignoring it."
(OpamConsole.colorise `bold "--no-autoinstall");
if all && command <> Some `list_available then
OpamConsole.warning "Option %s must be used with $(i,list-available), skipping"
(OpamConsole.colorise `bold "--all");
apply_global_options cli global_options;
apply_build_options cli build_options;
let invariant_arg ?repos rt args =
Expand Down Expand Up @@ -2886,16 +2895,26 @@ let switch cli =
patt))
pattlist
in
let compilers =
let all_compilers =
OpamListCommand.filter ~base:compilers st
(OpamFormula.ands (List.map (fun f -> OpamFormula.Atom f) filters))
in
let compilers =
if all then
all_compilers
else
OpamListCommand.filter ~base:all_compilers st
(OpamFormula.ands [
OpamFormula.Atom (OpamListCommand.NotFlag Pkgflag_AvoidVersion);
OpamFormula.Atom (OpamListCommand.NotFlag Pkgflag_Deprecated);
])
in
let format =
if print_short then OpamListCommand.([ Package ])
else OpamListCommand.([ Name; Version; Synopsis; ])
in
let order nv1 nv2 =
if nv1.version = nv2.version
if OpamPackage.Version.equal nv1.version nv2.version
then OpamPackage.Name.compare nv1.name nv2.name
else OpamPackage.Version.compare nv1.version nv2.version
in
Expand All @@ -2909,6 +2928,10 @@ let switch cli =
order = `Custom order;
}
compilers;
if not all && not (OpamPackage.Set.equal all_compilers compilers) then
OpamConsole.note
"Some compilers have been hidden (e.g. pre-releases). \
If you want to display them, run: 'opam switch list-available --all'";
`Ok ()
| Some `install, switch_arg::params ->
OpamGlobalState.with_ `Lock_write @@ fun gt ->
Expand Down Expand Up @@ -3161,7 +3184,7 @@ let switch cli =
$print_short_flag cli cli_original
$no_switch
$packages $formula $empty $descr $full $freeze $no_install
$deps_only $repos $force $no_action $d_alias_of $d_no_autoinstall
$deps_only $repos $force $no_action $all $d_alias_of $d_no_autoinstall
$params)

(* PIN *)
Expand Down
48 changes: 48 additions & 0 deletions tests/reftests/switch-list-available.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ comp-b 1
comp-a 2
comp-a 3
comp-a 4
### opam switch list-available --all
# Listing available compilers from repositories: default
# Name # Version # Synopsis
comp-a 1
comp-b 1
comp-a 2
comp-a 3
comp-a 4
### <pkg:comp-b.2>
opam-version: "2.0"
flags: [compiler avoid-version]
Expand All @@ -43,6 +51,16 @@ flags: compiler
comp-a 1
comp-b 1
comp-a 2
comp-a 3
comp-a 4
comp-b 4
[NOTE] Some compilers may have been hidden (e.g. pre-releases). If you want to display them, run: 'opam switch list-available --all'
### opam switch list-available --all
# Listing available compilers from repositories: default
# Name # Version # Synopsis
comp-a 1
comp-b 1
comp-a 2
comp-b 2
comp-a 3
comp-b 3
Expand All @@ -52,19 +70,34 @@ comp-b 4
### opam switch list-available pkg-1
# Listing available compilers from repositories: default
# No matches found
### opam switch list-available pkg-1 --all
# Listing available compilers from repositories: default
# No matches found
### opam switch list-available comp-b
# Listing available compilers from repositories: default
# Name # Version # Synopsis
comp-b 1
comp-b 4
[NOTE] Some compilers may have been hidden (e.g. pre-releases). If you want to display them, run: 'opam switch list-available --all'
### opam switch list-available comp-b --all
# Listing available compilers from repositories: default
# Name # Version # Synopsis
comp-b 1
comp-b 2
comp-b 3
comp-b 4
### opam switch list-available comp-b.1
# Listing available compilers from repositories: default
# No matches found
### opam switch list-available comp-b.1 --all
# Listing available compilers from repositories: default
# No matches found
### opam switch list-available comp-b.2
# Listing available compilers from repositories: default
# No matches found
### opam switch list-available comp-b.2 --all
# Listing available compilers from repositories: default
# No matches found
### <pkg:comp_c.1>
opam-version: "2.0"
flags: compiler
Expand All @@ -80,6 +113,16 @@ flags: [compiler avoid-version]
comp-a 1
comp-b 1
comp-a 2
comp-a 3
comp-a 4
comp-b 4
[NOTE] Some compilers may have been hidden (e.g. pre-releases). If you want to display them, run: 'opam switch list-available --all'
### opam switch list-available "comp-*" --all
# Listing available compilers from repositories: default
# Name # Version # Synopsis
comp-a 1
comp-b 1
comp-a 2
comp-b 2
comp-a 3
comp-b 3
Expand All @@ -89,4 +132,9 @@ comp-b 4
# Listing available compilers from repositories: default
# Name # Version # Synopsis
comp_c 1
[NOTE] Some compilers may have been hidden (e.g. pre-releases). If you want to display them, run: 'opam switch list-available --all'
### opam switch list-available "comp_*" --all
# Listing available compilers from repositories: default
# Name # Version # Synopsis
comp_c 1
comp_c 2

0 comments on commit 3f40f9e

Please sign in to comment.