From 25bee6a71216a828674314a271b8664eb7468b56 Mon Sep 17 00:00:00 2001 From: Raja Boujbel Date: Thu, 4 Mar 2021 16:40:47 +0100 Subject: [PATCH 1/4] cli: fix some versioning checks --- src/client/opamArg.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/opamArg.ml b/src/client/opamArg.ml index 523d475df5a..5fc8c1e4d95 100644 --- a/src/client/opamArg.ml +++ b/src/client/opamArg.ml @@ -1001,7 +1001,7 @@ end = struct let doc = Arg.info ?docs:section ~docv:value ~doc flags in let check elem = check_cli_validity cli validity - ~cond:(fun c -> c && default != elem) elem flags + ~cond:(fun c -> c && default <> elem) elem flags in term_cli_check ~check Arg.(opt ?vopt kind default & doc) @@ -1011,7 +1011,7 @@ end = struct let doc = Arg.info ?docs:section ~docv:value ~doc flags in let check elem = check_cli_validity cli validity - ~cond:(fun c -> c && default != elem) elem flags + ~cond:(fun c -> c && default <> elem) elem flags in term_cli_check ~check Arg.(opt_all ?vopt kind default & doc) From 9eb0cf3f98ca6cbe6129f5db13a14f9710ee93db Mon Sep 17 00:00:00 2001 From: Raja Boujbel Date: Thu, 4 Mar 2021 17:43:49 +0100 Subject: [PATCH 2/4] cli version: add flag deprecation and replacement helper --- src/client/opamArg.ml | 22 ++++++++++++++-------- src/client/opamArg.mli | 6 ++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/client/opamArg.ml b/src/client/opamArg.ml index 5fc8c1e4d95..5ed94898111 100644 --- a/src/client/opamArg.ml +++ b/src/client/opamArg.ml @@ -805,6 +805,10 @@ module Mk : sig cli:OpamCLIVersion.Sourced.t -> validity -> ?section:string -> string list -> string -> bool Term.t + val mk_flag_replaced: + cli:OpamCLIVersion.Sourced.t -> ?section:string -> (validity * string list) list -> + string -> bool Term.t + val mk_opt: cli:OpamCLIVersion.Sourced.t -> validity -> ?section:string -> ?vopt:'a -> string list -> string -> string -> 'a Arg.converter -> 'a -> 'a Term.t @@ -1035,6 +1039,10 @@ end = struct in term_cli_check ~check Arg.(vflag (`Valid default) info_flags) + let mk_flag_replaced ~cli ?section flags doc = + let flags = List.map (fun (c,f) -> c, true, f, doc) flags in + mk_vflag ~cli ?section false flags + let mk_vflag_all ~cli ?section ?(default=[]) flags = let flags = List.map (fun (v,c,f,d) -> contented_validity v c, f, d) flags in let info_flags = @@ -1632,14 +1640,12 @@ let build_options cli = Arg.(some (list package_name)) None ~vopt:(Some []) in let unlock_base = - mk_vflag ~cli ~section false ([ - cli_between cli2_0 cli2_1 ~replaced:"--update-invariant", true, ["unlock-base"] ; - cli_from cli2_1, true, ["update-invariant"] - ] |> List.map (fun (c,v,f) -> - c,v,f, - "Allow changes to the packages set as switch base (typically, the main \ - compiler). Use with caution. This is equivalent to setting the \ - $(b,\\$OPAMUNLOCKBASE) environment variable")) + mk_flag_replaced ~cli ~section [ + cli_between cli2_0 cli2_1 ~replaced:"--update-invariant", ["unlock-base"]; + cli_from cli2_1, ["update-invariant"] + ] "Allow changes to the packages set as switch base (typically, the main \ + compiler). Use with caution. This is equivalent to setting the \ + $(b,\\$OPAMUNLOCKBASE) environment variable" in let locked = locked cli ~section in let lock_suffix = lock_suffix cli ~section in diff --git a/src/client/opamArg.mli b/src/client/opamArg.mli index 6db61d93eaf..8671241fe2d 100644 --- a/src/client/opamArg.mli +++ b/src/client/opamArg.mli @@ -51,6 +51,12 @@ val mk_flag: ?section:string -> string list -> string -> bool Term.t +(* Deprecate and replace a [flags]. Constructs a [vflag] with the deprecated + option and the new one *) +val mk_flag_replaced: + cli:OpamCLIVersion.Sourced.t -> ?section:string -> (validity * string list) list -> + string -> bool Term.t + val mk_opt: cli:OpamCLIVersion.Sourced.t -> validity -> ?section:string -> ?vopt:'a -> string list -> string -> string -> From e328736f3eddb21813d067cf39696cf90ab0681f Mon Sep 17 00:00:00 2001 From: Raja Boujbel Date: Fri, 19 Mar 2021 16:19:56 +0100 Subject: [PATCH 3/4] update changes --- master_changes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/master_changes.md b/master_changes.md index 1767f51d62b..9fc526bb413 100644 --- a/master_changes.md +++ b/master_changes.md @@ -112,6 +112,7 @@ New option/command/subcommand are prefixed with ◈. * Generalise `mk_tristate_opt' to mk_state_opt [#4575 @rjbou] * Fix `opam exec` on native Windows when calling cygwin executables [#4588 @AltGr] * Fix temporary file with a too long name causing errors on Windows [#4590 @AltGr] + * CLI: Add flag deprecation and replacement helper [#4595 @rjbou] ## Test * Make the reference tests dune-friendly [#4376 @emillon] From 8167b59019462e40ebaa31655b44b3cecc3d48a0 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Thu, 11 Mar 2021 14:08:00 +0000 Subject: [PATCH 4/4] Rename opam list --silent to --check Retain --silent in the default CLI. --- master_changes.md | 2 +- src/client/opamCommands.ml | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/master_changes.md b/master_changes.md index 9fc526bb413..15cdbe20f36 100644 --- a/master_changes.md +++ b/master_changes.md @@ -34,7 +34,7 @@ New option/command/subcommand are prefixed with ◈. sense with 2.1 switch invariants) [#4571 @dra27] ## List - * + * --silent renamed to --check [#4595 @dra27 - fix #4323] ## Show * diff --git a/src/client/opamCommands.ml b/src/client/opamCommands.ml index 9d557714498..4e7084ce13d 100644 --- a/src/client/opamCommands.ml +++ b/src/client/opamCommands.ml @@ -532,8 +532,10 @@ let list ?(force_search=false) cli = OpamArg.variable_bindings [] in let silent = - mk_flag ~cli cli_original ["silent"] - "Don't write anything in the output, exit with return code 0 if the list \ + mk_flag_replaced ~cli [ + cli_between ~default:true cli2_0 cli2_1 ~replaced:"--check", ["silent"]; + cli_from cli2_1, ["check"] + ] "Don't write anything in the output, exit with return code 0 if the list \ is not empty, 1 otherwise." in let no_depexts =