Collapse all repl-* options into :repl-options map

Makes progress on #432, still may need work (needs test cases).

Also note all non-lein keys in :repl-options are passed through to
reply without modification (in case reply adds some crazy new features
that lein doesn't immediately support)
This commit is contained in:
Lee Hinman 2012-04-10 17:09:20 -06:00
parent eb745d06b0
commit c6697f76aa
2 changed files with 41 additions and 23 deletions

View file

@ -89,16 +89,20 @@
;; run task or shell wrappers without bringing in AOT if you don't need an
;; executable uberjar.
:main org.example.sample
;; This namespace will get loaded automatically when you launch a repl.
:repl-init sample.repl-helper
;; These will get passed to clojure.main/repl; see its docstring for details.
:reply-options [:prompt (fn [] (print "your command, master? ") (flush))]
;; Customize the socket the repl task listens on.
:repl-port 4001
:repl-host "0.0.0.0"
;; If your -main namespace takes a long time to load, it could time out the
;; repl connection. Increase this to give it more time. Defaults to 100.
:repl-retry-limit 1000
;; Options to change the way the REPL behaves
:repl-options {;; These will get passed to clojure.main/repl; see
;; its docstring for details.
:prompt (fn [ns] (print "your command, master?" ns) (flush))
;; This expression will be run when first opening a REPL.
:init (in-ns 'foo.bar)
;; Customize the socket the repl task listens on and
;; attaches to.
:host "0.0.0.0"
:port 4001
;; If nREPL takes too long to load it may timeout,
;; increase this to wait longer before timing out.
;; Defaults to 30000 (30 seconds)
:timeout 40000}
;; Forms to prepend to every form that is evaluated inside your project.
;; Allows working around the Gilardi Scenario: http://technomancy.us/143
:injections [(require 'clojure.pprint)]

View file

@ -1,6 +1,7 @@
(ns leiningen.repl
"Start a repl session either with the current project or standalone."
(:require clojure.main
clojure.set
[reply.main :as reply]
[clojure.java.io :as io]
[leiningen.core.eval :as eval]
@ -38,24 +39,28 @@
(defn- repl-port [project]
(Integer. (or (System/getenv "LEIN_REPL_PORT")
(:repl-port project)
(-> project :repl-options :port)
0)))
(defn- repl-host [project]
(or (System/getenv "LEIN_REPL_PORT")
(-> project :repl-options :host)))
(defn- ack-port [project]
(when-let [p (or (System/getenv "LEIN_REPL_ACK_PORT")
(:repl-ack-port project))]
(-> project :repl-options :ack-port))]
(Integer. p)))
(defn ^:no-project-needed repl
"Start a repl session either with the current project or standalone.
USAGE: lein repl
This will launch an nREPL server behind the scenes that reply will connect to.
If a :repl-port key is present in project.clj, that port will be used for the
server, otherwise it is chosen randomly. If you run this command inside of a
project, it will be run in the context of that classpath. If the command is
run outside of a project, it'll be standalone and the classpath will be
that of Leiningen.
USAGE: lein repl This will launch an nREPL server behind the scenes
that reply will connect to. If a :port key is present in
the :repl-options map in project.clj, that port will be used for the
server, otherwise it is chosen randomly. If you run this command
inside of a project, it will be run in the context of that classpath.
If the command is run outside of a project, it'll be standalone and
the classpath will be that of Leiningen.
USAGE: lein repl :headless
This will launch an nREPL server and wait, rather than connecting reply to it.
@ -70,13 +75,22 @@ and port."
(.start
(Thread.
(bound-fn []
(start-server (and project (vary-meta project assoc :prepped prepped))
(start-server (and project (vary-meta project assoc
:prepped prepped))
(repl-port project)
(-> @lein-repl-server deref :ss .getLocalPort)))))
(and project @prepped)
(if-let [repl-port (nrepl.ack/wait-for-ack (:repl-timeout project 30000))]
(reply/launch-nrepl (merge {:attach (str repl-port)}
(:reply-options project)))
(if-let [repl-port (nrepl.ack/wait-for-ack (or (-> project
:repl-options
:timeout)
30000))]
(reply/launch-nrepl (clojure.set/rename-keys
(assoc (:repl-options project)
:attach (if-let [host (repl-host project)]
(str host ":" repl-port)
(str repl-port)))
{:prompt :custom-prompt
:init :custom-init}))
(println "REPL server launch timed out."))))
([project flag & opts]
(case flag