Skip to content

Change to make "cljr swank" default to safer localhost #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/resources/cljr/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions src/main/resources/cljr/swank.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))