-
Notifications
You must be signed in to change notification settings - Fork 347
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
Print shell-appropriate eval command on opam init
#4427
Conversation
Thanks for picking up the pieces of #3274! It's a better idea than I did in that PR to split the I think you then want You then want a new function If you want, you could also use those functions for a version of b4b3fca (which tries to the use the correct "guessed" eval string in help text output too) |
Hey David, thanks for the detailed comment! I've tried to express your suggestions in 8340e6e, hopefully I didn't misunderstand. In terms of using the functions for I see how b4b3fca used OpamEnv.(
shell_eval_invocation shell
(opam_env_invocation ~switch:"SWITCH" ~set_opamswitch:true ())
|> Manpage.escape) |
a30699a
to
4c9fe66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies for not responding to your message a bit more quickly, but thank you for rebasing and updating this in the meantime. The implementation is exactly what I had in mind - the suggestions below are just possibly to use OpamStd.Option
to reduce some of the match
es on options.
This is basically ready to merge - thanks for taking on my stale PR and improving it!
src/state/opamEnv.ml
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly more concise as:
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") "" r in | |
let switch = OpamStd.Option.map_default (Printf.sprintf " --switch=%s") "" s in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, applied (r and s converted to "root" and "switch")
src/state/opamEnv.ml
Outdated
else | ||
"" in | ||
None | ||
in | ||
let switch = | ||
match switch with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be refactored slightly more clearly as:
let f sw =
let sw_cur = ... (* etc. code from the `Some sw` case *)
in
OpamStd.Option.replace f switch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, refactored
a5f60bc
to
184ab77
Compare
184ab77
to
b44030e
Compare
Thank you for the review! |
Lovely, thank you! |
(The mingw64 failure is nothing to do this PR) |
This change is similar in spirit to 46eab70 (an open pull request marked as obsolete) with a slightly different implementation.
I'm new to OCaml and been following the instructions to install
opam
, duringopam init
it prints a shell-dependent line that will be added, but incorrectly printseval $(opam env)
(I usefish
so that should beeval (opam env)
):Let me know if the change is not idiomatic, since I just installed
opam
andocaml
and have no previous experience with either.