Skip to content

Commit

Permalink
dev: add --host to dev:bb and dev:jvm tasks (#580)
Browse files Browse the repository at this point in the history
Allows developer to specify `--host 0.0.0.0` to allow anyone to remotely
connect. Handy when debugging behaviour on VM or other computer.

Closes #578
  • Loading branch information
lread authored May 15, 2024
1 parent 1de58c3 commit d8e3eba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
17 changes: 14 additions & 3 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
:tasks
{;; setup
:requires ([babashka.classpath :as cp]
[babashka.cli :as cli]
[babashka.fs :as fs]
[clojure.string :as string]
[helper.shell :as shell]
[lread.status-line :as status])
:init (do (defn parse-repl-args [args]
(let [cli-spec {:spec
{:host {:desc "Bind to host (use 0.0.0.0 to allow anyone to connect)"
:alias :h
:default "localhost"}}
:restrict true}]
(cli/parse-opts args cli-spec))))
:enter (let [{:keys [name]} (current-task)]
(when-not (string/starts-with? name "-")
(status/line :head "TASK %s %s" name (string/join " " *command-line-args*))))
Expand All @@ -21,16 +29,19 @@

;; commands
dev:jvm {:doc "start a Clojure nrepl server/prompt"
:task (shell/command "clj" "-M:test:repl/cider")}
:task (let [opts (parse-repl-args *command-line-args*)
host (:host opts)]
(shell/command "clj" "-M:test:repl/cider" "-h" host "-b" host))}
dev:bb {:doc "start a Babashka nrepl server"
;; repeat :test paths from deps.edn
:extra-paths ["test" "env/test/resources"]
:extra-deps {;; inherit base deps from deps.edn
etaoin/etaoin {:local/root "."}
;; repeat necessary :test deps from deps.edn
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
:task (do (babashka.nrepl.server/start-server!)
(deref (promise)))}
:task (let [opts (parse-repl-args *command-line-args*)]
(babashka.nrepl.server/start-server! opts)
(deref (promise)))}
test:jvm {:doc "Runs tests under JVM Clojure [--help]"
:task test/test-jvm}
-test:bb {:doc "bb test runner, invoked within script/test.clj"
Expand Down
9 changes: 9 additions & 0 deletions doc/02-developer-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ For a babashka REPL
bb dev:bb
----

By default you can only connect to the REPL from localhost.
If you need to connect to a REPL running on a different host, launch your REPL with `--host`.
For example, to allow anyone to connect to your REPL:

[source,shell]
----
bb dev:jvm --host 0.0.0.0
----

=== Checking Tools Versions

Used by GitHub Actions, but also an interesting way to check your prerequisites:
Expand Down

0 comments on commit d8e3eba

Please sign in to comment.