Skip to content

Commit a762792

Browse files
committed
Show a working opam switch create command when opam init fails to create the default switch
1 parent 40d1989 commit a762792

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/client/opamCommands.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,24 @@ let init cli =
541541
~additional_installs:default_compiler)
542542
with e ->
543543
OpamStd.Exn.finalise e @@ fun () ->
544+
let invariant_str = match invariant with
545+
| OpamFormula.Atom (name, Empty) ->
546+
OpamPackage.Name.to_string name
547+
| OpamFormula.Atom (name, Atom (op, v)) ->
548+
"'" ^
549+
OpamPackage.Name.to_string name ^
550+
OpamFormula.string_of_relop op ^
551+
OpamPackage.Version.to_string v ^
552+
"'"
553+
| formula ->
554+
"--formula '" ^ OpamFormula.to_string formula ^ "'"
555+
in
544556
OpamConsole.note
545557
"Opam has been initialised, but the initial switch creation \
546558
failed.\n\
547-
Use 'opam switch create <compiler>' to get started."
559+
Use %s to get started."
560+
(OpamConsole.colorise `bold
561+
("opam switch create default "^invariant_str))
548562
in
549563
OpamSwitchState.drop st
550564
in

0 commit comments

Comments
 (0)