diff --git a/master_changes.md b/master_changes.md index 1ba9be04daf..927d6efea0b 100644 --- a/master_changes.md +++ b/master_changes.md @@ -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 diff --git a/src/client/opamCommands.ml b/src/client/opamCommands.ml index 095b23e1480..4a446b80e5e 100644 --- a/src/client/opamCommands.ml +++ b/src/client/opamCommands.ml @@ -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) @@ -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 @@ -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 = @@ -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 @@ -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 -> @@ -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 *) diff --git a/tests/reftests/switch-list-available.test b/tests/reftests/switch-list-available.test index e1d93438772..6e5df9110ef 100644 --- a/tests/reftests/switch-list-available.test +++ b/tests/reftests/switch-list-available.test @@ -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 ### opam-version: "2.0" flags: [compiler avoid-version] @@ -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 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 @@ -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 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 ### opam-version: "2.0" flags: compiler @@ -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 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 @@ -89,4 +132,9 @@ comp-b 4 # Listing available compilers from repositories: default # Name # Version # Synopsis comp_c 1 +[NOTE] Some compilers 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