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

Introduce `--confirm-level' option #4582

Merged
merged 11 commits into from
May 26, 2021
5 changes: 5 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ New option/command/subcommand are prefixed with ◈.
* Clearer messages about using --cli and OPAMCLI [#4655 @dra27]
* The options `--root` and `--switch` are now reflected in environment variables when building packages
so that calls to `opam` during build access the correct root and switch [#4668 @LasseBlaauwbroek]
* Add cli versioning for enums of flags with predefined enums [#4626 @rjbou]
* ◈ Add `--confirm-level` and `OPAMCONFIRMLEVEL` [#4582 @rjbou - fix #4168]
rjbou marked this conversation as resolved.
Show resolved Hide resolved
* ◈ Add `--no` [#4582 @rjbou]
* Initialise environment variables for plugins call/install [#4582 @rjbou]

## Init
* Introduce a `default-invariant` config field, restore the 2.0 semantics for
Expand Down Expand Up @@ -142,6 +146,7 @@ New option/command/subcommand are prefixed with ◈.
## Internal
* Generalise `mk_tristate_opt` to `mk_state_opt` [#4575 @rjbou]
* Fix `mk_state_opt` and rename to `mk_enum_opt` [#4626 @rjbou]
* Add `mk_enum_opt_all` for state flags that appears more than once [#4582 @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]
Expand Down
74 changes: 58 additions & 16 deletions src/client/opamArg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ let when_enum =
[ "always", `Always; "never", `Never; "auto", `Auto ]
|> List.map (fun (s,v) -> cli_original, s, v)

let confirm_enum = [
cli_from cli2_1, "ask", `ask;
cli_from cli2_1, "no", `all_no;
cli_from cli2_1, "yes", `all_yes;
cli_from cli2_1, "unsafe-yes", `unsafe_yes;
]

(* Windows directory separators need to be escaped for manpages *)
let dir_sep, escape_path =
match Filename.dir_sep with
Expand All @@ -45,7 +52,10 @@ let preinit_environment_variables =
let open OpamCoreConfig.E in [
"DEBUG", (fun v -> DEBUG (env_int v)),
"see options `--debug' and `--debug-level'.";
"YES", (fun v -> YES (env_bool v)), "see option `--yes'.";
"YES", (fun v -> YES (env_bool v)),
"see options `--yes' and `--confirm-level`. \
$(b,OPAMYES) has has priority over $(b,OPAMNO) and is \
ignored if $(b,OPAMCONFIRMLEVEL) is set.";
] in
let client =
let open OpamClientConfig.E in [
Expand All @@ -57,7 +67,7 @@ let preinit_environment_variables =
] in
core @ client

let preinit_opam_envvariables, doc_opam_envvariables_pre =
let preinit_opam_env_variables, doc_opam_env_variables_pre =
let preinit () =
OpamStd.Config.E.updates @@
List.map (fun (var, cons, _doc) -> cons var)
Expand All @@ -80,6 +90,10 @@ let environment_variables =
"COLOR", cli_original, (fun v -> COLOR (env_when v)),
"when set to $(i,always) or $(i,never), sets a default value for the \
`--color' option.";
"CONFIRMLEVEL", cli_from cli2_1, (fun v -> CONFIRMLEVEL (env_answer v)),
"see option `--confirm-level`. \
$(b,OPAMCONFIRMLEVEL) has priority over $(b,OPAMYES) \
and $(b,OPAMNO).";
"DEBUGSECTIONS", cli_from cli2_1, (fun v -> DEBUGSECTIONS (env_sections v)),
"if set, limits debug messages to the space-separated list of \
sections. Sections can optionally have a specific debug level (for \
Expand All @@ -98,7 +112,9 @@ let environment_variables =
"MERGEOUT", cli_original, (fun v -> MERGEOUT (env_bool v)),
"merge process outputs, stderr on stdout.";
"NO", cli_original, (fun v -> NO (env_bool v)),
"answer no to any question asked.";
"answer no to any question asked, see options `--no` and `--confirm-level`. \
$(b,OPAMNO) is ignored if either $(b,OPAMCONFIRMLEVEL) or $(b,OPAMYES) \
is set.";
"PRECISETRACKING", cli_original, (fun v -> PRECISETRACKING (env_bool v)),
"fine grain tracking of directories.";
"SAFE", cli_original, (fun v -> SAFE (env_bool v)),
Expand Down Expand Up @@ -209,8 +225,6 @@ let environment_variables =
(fun v -> BUILDDOC (env_bool v)), "see option `--build-doc'.";
"BUILDTEST", cli_between cli2_0 cli2_1,
(fun v -> BUILDTEST (env_bool v)), "see option `--build-test'.";
"DEPEXTYES", cli_from cli2_1, (fun v -> DEPEXTYES (env_bool v)),
"launch system package managers in non-interactive mode.";
"DOWNLOADJOBS", cli_original, (fun v -> DOWNLOADJOBS (env_int v)),
"sets the maximum number of simultaneous downloads.";
"DRYRUN", cli_original, (fun v -> DRYRUN (env_bool v)),
Expand Down Expand Up @@ -296,7 +310,7 @@ let scrubbed_environment_variables =
in
OpamStd.List.filter_map f environment_variables

let doc_opam_envvariables, init_opam_envvariabes =
let doc_opam_env_variables, init_opam_env_variabes =
env_with_cli environment_variables

(** Help sections common to all commands *)
Expand All @@ -312,7 +326,7 @@ let help_sections cli =
variables should be set to \"0\", \"no\", \"false\" or the empty \
string to disable, \"1\", \"yes\" or \"true\" to enable.";
] @
List.sort compare (doc_opam_envvariables_pre @ doc_opam_envvariables cli)
List.sort compare (doc_opam_env_variables_pre @ doc_opam_env_variables cli)
@ [
`P "$(i,OPAMVAR_var) overrides the contents of the variable $(i,var) when \
substituting `%{var}%` strings in `opam` files.";
Expand Down Expand Up @@ -419,7 +433,7 @@ type global_options = {
quiet : bool;
color : OpamStd.Config.when_ option;
opt_switch : string option;
yes : bool;
answer : OpamStd.Config.answer option;
strict : bool;
opt_root : dirname option;
git_version : bool;
Expand All @@ -438,7 +452,9 @@ type global_options = {

(* The --cli passed by cmdliner is ignored (it's only there for --help) *)
let create_global_options
git_version debug debug_level verbose quiet color opt_switch yes strict
git_version debug debug_level verbose quiet color opt_switch
yes confirm_level
strict
opt_root external_solver use_internal_solver
cudf_file solver_preferences best_effort safe_mode json no_auto_upgrade
working_dir ignore_pin_depends
Expand All @@ -450,9 +466,16 @@ let create_global_options
let debug_level = OpamStd.Option.Op.(
debug_level >>+ fun () -> if debug then Some 1 else None
) in
let answer =
match List.rev confirm_level, List.rev yes with
| [], [] -> None
| [], true::_ -> Some `all_yes
| [], false::_ -> Some `all_no
| c::_ , _ -> Some c
in
let verbose = List.length verbose in
let cli = OpamCLIVersion.current in
{ git_version; debug_level; verbose; quiet; color; opt_switch; yes;
{ git_version; debug_level; verbose; quiet; color; opt_switch; answer;
strict; opt_root; external_solver; use_internal_solver;
cudf_file; solver_preferences; best_effort; safe_mode; json;
no_auto_upgrade; working_dir; ignore_pin_depends; cli }
Expand All @@ -476,7 +499,7 @@ let apply_global_options cli o =
o.external_solver >>| fun s -> lazy (OpamCudfSolver.solver_of_string s)
in
let solver_prefs = o.solver_preferences >>| fun p -> lazy (Some p) in
init_opam_envvariabes cli;
init_opam_env_variabes cli;
OpamClientConfig.opam_init
(* - format options - *)
?strict:(flag o.strict)
Expand All @@ -489,7 +512,7 @@ let apply_global_options cli o =
?color:o.color
(* ?utf8:[ `Extended | `Always | `Never | `Auto ] *)
(* ?disp_status_line:[ `Always | `Never | `Auto ] *)
?answer:(some (flag o.yes))
?answer:o.answer
?safe_mode:(flag o.safe_mode)
(* ?lock_retries:int *)
(* ?log_dir:OpamTypes.dirname *)
Expand Down Expand Up @@ -1128,9 +1151,27 @@ let global_options cli =
This is equivalent to setting $(b,\\$OPAMSWITCH) to $(i,SWITCH)."
Arg.(some string) None in
let yes =
mk_flag ~cli cli_original ~section ["y";"yes"]
"Answer yes to all yes/no questions without prompting. \
This is equivalent to setting $(b,\\$OPAMYES) to \"true\"." in
mk_vflag_all ~cli [
cli_original, true, ["y";"yes"],
"Answer yes to all opam yes/no questions without prompting. \
See also $(b,--confirm-level). \
This is equivalent to setting $(b,\\$OPAMYES) to \"true\".";
cli_from cli2_1, false, ["no"],
"Answer no to all opam yes/no questions without prompting. \
See also $(b,--confirm-level). \
This is equivalent to setting $(b,\\$OPAMNO) to \"true\".";
]
in
let confirm_level =
mk_enum_opt_all ~cli (cli_from cli2_1) ~section ["confirm-level"] "LEVEL"
confirm_enum
(Printf.sprintf
"Confirmation level, $(docv) must be %s. Can be specified more than \
once. If $(b,--yes) or $(b,--no) are also given, the value of the \
last $(b,--confirm-level) is taken into account. This is equivalent \
to setting $(b, \\$OPAMCONFIRMLEVEL)`."
(string_of_enum confirm_enum))
in
let strict =
mk_flag ~cli cli_original ~section ["strict"]
"Fail whenever an error is found in a package definition \
Expand Down Expand Up @@ -1225,7 +1266,8 @@ let global_options cli =
equivalent to setting $(b,IGNOREPINDEPENDS=true)."
in
Term.(const create_global_options
$git_version $debug $debug_level $verbose $quiet $color $switch $yes
$git_version $debug $debug_level $verbose $quiet $color $switch
$yes $confirm_level
$strict $root $external_solver
$use_internal_solver $cudf_file $solver_preferences $best_effort
$safe_mode $json_flag $no_auto_upgrade $working_dir
Expand Down
6 changes: 3 additions & 3 deletions src/client/opamArg.mli
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type global_options = {
quiet : bool;
color : OpamStd.Config.when_ option;
opt_switch : string option;
yes : bool;
answer : OpamStd.Config.answer option;
strict : bool;
opt_root : dirname option;
git_version : bool;
Expand Down Expand Up @@ -341,6 +341,6 @@ val help_sections: OpamCLIVersion.Sourced.t -> Manpage.block list

(** {2 Environment variables} *)

val preinit_opam_envvariables: unit -> unit
val init_opam_envvariabes: OpamCLIVersion.Sourced.t -> unit
val preinit_opam_env_variables: unit -> unit
val init_opam_env_variabes: OpamCLIVersion.Sourced.t -> unit
val scrubbed_environment_variables: string list
Loading