diff --git a/src/main/resources/cljr/main.clj b/src/main/resources/cljr/main.clj index ea6a78d..b5ac49f 100644 --- a/src/main/resources/cljr/main.clj +++ b/src/main/resources/cljr/main.clj @@ -23,7 +23,7 @@ \newline "* swingrepl: Starts a Clojure swingrepl." \newline \newline - "* swank [port]: Start a local swank server on port 4005 (or as specified)." \newline + "* swank [port [host]]: Start a local swank server on localhost port 4005 (or as specified)." \newline \newline "* run filename: Runs the given Clojure file." \newline \newline diff --git a/src/main/resources/cljr/swank.clj b/src/main/resources/cljr/swank.clj index d419581..9b63aae 100644 --- a/src/main/resources/cljr/swank.clj +++ b/src/main/resources/cljr/swank.clj @@ -3,11 +3,21 @@ (defn swank ([] - (swank 4005)) + (swank nil nil)) ([port] - (cond - (nil? port) (start-repl 4005) - (integer? port) (start-repl port) - (string? port) (start-repl (Integer/parseInt port 10)) - :else (println "Invalid port number: " port)))) + (swank port nil)) + ([port host] + (let [the-host (cond + (nil? host) "localhost" + (string? host) host + :else (do (println "Invalid hostname:" host) + nil)) + the-port (cond + (nil? port) 4005 + (integer? port) port + (string? port) (try (Integer/parseInt port 10) + (catch NumberFormatException ex + nil)))] + (when (and the-host the-port) + (start-repl the-port :host the-host)))))