Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Commit

Permalink
Fix lein module to exit upon exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Sep 11, 2013
1 parent 328a5fc commit 8851eb5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
7 changes: 4 additions & 3 deletions client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ let rec handler (r,w,p) raw resp =
handler (r,w,p) raw tl
| [] -> ()

let eval port ns form =
let _ = Nrepl.new_session "127.0.0.1" port [eval_message form ns] handler in
let eval port messages =
let _ = Nrepl.new_session "127.0.0.1" port messages handler in
never_returns (Scheduler.go ())

(* invoking main functions *)
Expand Down Expand Up @@ -140,4 +140,5 @@ let main port args =
match args with
| [] -> eprintf "Missing ns argument."; exit 1
| ns :: args -> let form = main_form ns (splice_args args) in
eval port "user" form
let messages = [eval_message form "user"] in
eval port messages
16 changes: 11 additions & 5 deletions lein.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ let repl_port () =
| `Yes -> int_of_string (In_channel.read_all filename)
| `No | `Unknown -> eprintf "%s%!" port_err; exit 1

let ns = "leiningen.core.main"

let form = sprintf "(binding [*cwd* \"%s\", *exit-process?* false]
(System/setProperty \"leiningen.original.pwd\" \"%s\")
Expand All @@ -37,9 +35,17 @@ let form = sprintf "(binding [*cwd* \"%s\", *exit-process?* false]
(when-not (and (number? c) (zero? c))
(throw e))))))"

let main args =
let main_message args session =
let cwd = Sys.getcwd () in
let root = Client.find_root cwd cwd in
let port = repl_port () in
let form = form root cwd (Client.splice_args args) in
Client.eval port "leiningen.core.main" form
([("session", session);
("op", "eval");
("id", "main");
("ns", "leiningen.core.main");
("code", form)],
Nrepl.exit_actions)

let main args =
let port = repl_port () in
Client.eval port [main_message args]
3 changes: 3 additions & 0 deletions nrepl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ let default_actions =
let quiet_actions =
{ default_actions with out = do_nothing; }

let exit_actions =
{ quiet_actions with ex = fun e -> Pervasives.exit 1 }

let print_all =
{ default_actions with value = Printf.printf "%s\n%!"; }

Expand Down

0 comments on commit 8851eb5

Please sign in to comment.