Skip to content

Commit

Permalink
Resolve review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
freevoid committed Dec 20, 2020
1 parent a13ee93 commit a5f60bc
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions src/state/opamEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,8 @@ let shell_eval_invocation shell cmd =
(** Returns "opam env" invocation string together with optional root and switch
overrides *)
let opam_env_invocation ?root ?switch ?(set_opamswitch=false) () =
let root =
match root with
| None -> ""
| Some r -> Printf.sprintf " --root=%s" r
in
let switch =
match switch with
| None -> ""
| Some s -> Printf.sprintf " --switch=%s" s
in
let root = OpamStd.Option.map_default (Printf.sprintf " --root=%s") "" root in
let switch = OpamStd.Option.map_default (Printf.sprintf " --switch=%s") "" switch in
let setswitch = if set_opamswitch then " --set-switch" else "" in
Printf.sprintf "opam env%s%s%s" root switch setswitch

Expand All @@ -374,21 +366,21 @@ let eval_string gt ?(set_opamswitch=false) switch =
else
None
in
let switch =
match switch with
| None -> None
| Some sw ->
let sw_cur = OpamSwitch.to_string sw in
let sw_env =
OpamStd.Option.Op.(
OpamStd.Env.getopt "OPAMSWITCH" ++
(OpamStateConfig.get_current_switch_from_cwd gt.root >>|
OpamSwitch.to_string) ++
(OpamFile.Config.switch gt.config >>| OpamSwitch.to_string)
)
in
if Some sw_cur <> sw_env then Some sw_cur else None
(* Returns the switch only if it is different from the one determined by the
environment *)
let overriden_switch sw =
let sw_cur = OpamSwitch.to_string sw in
let sw_env =
OpamStd.Option.Op.(
OpamStd.Env.getopt "OPAMSWITCH" ++
(OpamStateConfig.get_current_switch_from_cwd gt.root >>|
OpamSwitch.to_string) ++
(OpamFile.Config.switch gt.config >>| OpamSwitch.to_string)
)
in
if Some sw_cur <> sw_env then Some sw_cur else None
in
let switch = OpamStd.Option.replace overriden_switch switch in
let shell = OpamStd.Sys.guess_shell_compat () in
shell_eval_invocation shell (opam_env_invocation ?root ?switch ~set_opamswitch ())

Expand Down

0 comments on commit a5f60bc

Please sign in to comment.