From bd008f800e0e3edc226f37be521db8eb31415965 Mon Sep 17 00:00:00 2001 From: Jim Crossley Date: Tue, 1 Oct 2013 15:18:25 -0400 Subject: [PATCH] Fallback to .nrepl-port for 'repl :connect' subtask --- src/leiningen/repl.clj | 8 +++++++- test/leiningen/test/repl.clj | 3 ++- test_projects/sample/.nrepl-port | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test_projects/sample/.nrepl-port diff --git a/src/leiningen/repl.clj b/src/leiningen/repl.clj index 390d4aa6..6c13c4b7 100644 --- a/src/leiningen/repl.clj +++ b/src/leiningen/repl.clj @@ -39,11 +39,17 @@ (-> project :repl-options :host) "127.0.0.1")) +(defn client-repl-port [project] + (let [port (repl-port project)] + (if (= port 0) + (slurp (io/file (:root project) ".nrepl-port")) + port))) + (defn connect-string [project opts] (as-> (str (first opts)) x (s/split x #":") (remove s/blank? x) - (-> (drop-last (count x) [(repl-host project) (repl-port project)]) + (-> (drop-last (count x) [(repl-host project) (client-repl-port project)]) (concat x)) (s/join ":" x))) diff --git a/test/leiningen/test/repl.clj b/test/leiningen/test/repl.clj index 44124e26..d4bcd90e 100644 --- a/test/leiningen/test/repl.clj +++ b/test/leiningen/test/repl.clj @@ -73,7 +73,8 @@ "" "repl-host:5" "7" "repl-host:7" "myhost:9" "myhost:9" - "http://localhost:20" "http://localhost:20")) + "http://localhost:20" "http://localhost:20") + (is (= "127.0.0.1:4242" (connect-string lthelper/sample-project [])))) (deftest test-options-for-reply (is (= (lthelper/fix-path-delimiters "/home/user/.lein-repl-history") diff --git a/test_projects/sample/.nrepl-port b/test_projects/sample/.nrepl-port new file mode 100644 index 00000000..629d685d --- /dev/null +++ b/test_projects/sample/.nrepl-port @@ -0,0 +1 @@ +4242 \ No newline at end of file