Skip to content

Commit

Permalink
var: get switch defined before global one
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Mar 27, 2019
1 parent 551de1a commit c392669
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/client/opamConfigCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -315,32 +315,35 @@ let set_global var value =
OpamGlobalState.write { gt with config }

let variable gt v =
match OpamPackageVar.resolve_global gt v with
| Some c ->
OpamConsole.msg "%s\n" (OpamVariable.string_of_variable_contents c)
| None ->
let raw_switch_content =
match OpamStateConfig.get_switch_opt () with
| None ->
OpamConsole.error_and_exit `Not_found
"Variable %s not found"
(OpamVariable.Full.to_string v)
| Some switch ->
let switch_config =
OpamFile.Switch_config.safe_read
(OpamPath.Switch.switch_config gt.root switch)
in
match OpamPackageVar.resolve_switch_raw gt switch switch_config v with
| Some c ->
OpamConsole.msg "%s\n" (OpamVariable.string_of_variable_contents c)
| None ->
OpamSwitchState.with_ `Lock_none gt @@ fun st ->
match OpamPackageVar.resolve st v with
| Some c ->
OpamConsole.msg "%s\n" (OpamVariable.string_of_variable_contents c)
| None ->
OpamConsole.error_and_exit `Not_found
"Variable %s not found"
(OpamVariable.Full.to_string v)
OpamPackageVar.resolve_switch_raw gt switch switch_config v
| None -> None
in
let switch_content =
match raw_switch_content with
| None when not (OpamVariable.Full.is_global v) ->
OpamSwitchState.with_ `Lock_none gt @@ fun st ->
OpamPackageVar.resolve st v
| rsc -> rsc
in
let content =
match switch_content with
| Some _ as some -> some
| None -> OpamPackageVar.resolve_global gt v
in
match content with
| Some c -> OpamConsole.msg "%s\n" (OpamVariable.string_of_variable_contents c)
| None ->
OpamConsole.error_and_exit `Not_found
"Variable %s not found"
(OpamVariable.Full.to_string v)


let exec gt ?set_opamroot ?set_opamswitch ~inplace_path command =
log "config-exec command=%a" (slog (String.concat " ")) command;
Expand Down

0 comments on commit c392669

Please sign in to comment.