Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename opam list --silent to opam list --check #4595

Merged
merged 4 commits into from
Mar 23, 2021
Merged
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
3 changes: 2 additions & 1 deletion master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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]
Expand Down
26 changes: 16 additions & 10 deletions src/client/opamArg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1001,7 +1005,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)

Expand All @@ -1011,7 +1015,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)

Expand All @@ -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 =
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/client/opamArg.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
6 changes: 4 additions & 2 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down