Merge pull request #1223 from kanej/hostreplarg

Add :host as an option to 'lein repl :start' and 'lein repl :headless' commands
This commit is contained in:
Phil Hagelberg 2013-06-14 12:36:42 -07:00
commit a41c7e4bd0
2 changed files with 35 additions and 11 deletions

View file

@ -14,8 +14,14 @@
[leiningen.trampoline :as trampoline]
[reply.main :as reply]))
(defn lookup-opt [opt-key opts]
(second (drop-while #(not= % opt-key) opts)))
(defn opt-host [opts]
(lookup-opt ":host" opts))
(defn opt-port [opts]
(if-let [port (second (drop-while #(not= % ":port") opts))]
(if-let [port (lookup-opt ":port" opts)]
(Integer/valueOf port)))
(defn ack-port [project]
@ -117,7 +123,8 @@
(:target-path project)))
(:target-path project)
(user/leiningen-home)) "repl-port")]
(when ~start-msg? (println "nREPL server started on port" port#))
(when ~start-msg?
(println "nREPL server started on port" port# "on host" ~(:host cfg)))
(spit repl-port-file# port#)
(.deleteOnExit repl-port-file#)
@(promise))
@ -171,7 +178,8 @@
(when headless? @(promise))
(if-let [repl-port (nrepl.ack/wait-for-ack
(-> project :repl-options (:timeout 60000)))]
(do (println "nREPL server started on port" repl-port) repl-port)
(do (println "nREPL server started on port" repl-port "on host" (:host cfg))
repl-port)
(main/abort "REPL server launch timed out."))))
(defn client [project attach]
@ -186,13 +194,16 @@ Subcommands:
<none> -> :start
:start [:port port] This will launch an nREPL server and connect a
client to it. If the :port key is specified, or present under
:repl-options in the project map, that port will be used for the
server, otherwise it is chosen randomly. When starting outside of a
project, the nREPL server will run internally to Leiningen.
:start [:host host] [:port port] This will launch an nREPL server
and connect a client to it. If the :host key is given, or present
under :repl-options, that host will be attached to, defaulting
to localhost otherwise, which will block remote connections.
If the :port key is given, or present under :repl-options in
the project map, that port will be used for the server, otherwise
it is chosen randomly. When starting outside of a project,
the nREPL server will run internally to Leiningen.
:headless [:port port]
:headless [:host host] [:port port]
This will launch an nREPL server and wait, rather than connecting
a client to it.
@ -211,7 +222,7 @@ Subcommands:
(if (= subcommand ":connect")
(client project (doto (connect-string project opts)
(->> (println "Connecting to nREPL at"))))
(let [cfg {:host (repl-host project)
(let [cfg {:host (or (opt-host opts) (repl-host project))
:port (or (opt-port opts) (repl-port project))}]
(case subcommand
":start" (if trampoline/*trampoline?*

View file

@ -15,12 +15,25 @@
:repl-options :ack-port)
2)))
(deftest test-opt-host
(are [in exp] (= exp (opt-host in))
[":host" "0.0.0.0"] "0.0.0.0"
[":host" "1.1.1.1"] "1.1.1.1"
[":foo" ":host" "0.0.0.0"] "0.0.0.0"
[":host" "0.0.0.0" ":foo"] "0.0.0.0"
["0.0.0.0"] nil
[":host"] nil
[":port" "0.0.0.0"] nil
[] nil
nil nil))
(deftest test-opt-port
(are [in exp] (= exp (opt-port in))
[":port" "1"] 1
[":foo" ":port" "1"] 1
[":port" "1" ":foo"] 1
["1"] nil))
["1"] nil
[] nil))
(deftest test-ack-port
(let [env "5"