Support new syntax in babashka.deps/clojure (#1440)

This commit is contained in:
Michiel Borkent 2022-12-07 10:04:40 +01:00 committed by GitHub
parent cd3252796e
commit 69db7105e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 22 deletions

View file

@ -27,25 +27,28 @@
(-> @(clojure) :exit) starts a clojure REPL, waits for it
to finish and returns the exit code from the process."
([] (clojure []))
([args] (clojure args nil))
([args opts]
(let [opts (merge {:in :inherit
:out :inherit
:err :inherit
:shutdown p/destroy-tree}
opts)]
(binding [*in* @sci/in
*out* @sci/out
*err* @sci/err
deps/*dir* (:dir opts)
deps/*env* (:env opts)
deps/*extra-env* (:extra-env opts)
deps/*process-fn* (fn
([cmd] (pp/process cmd opts))
([cmd _] (pp/process cmd opts)))
deps/*exit-fn* (fn
([_])
([_exit-code msg]
(throw (Exception. msg))))]
(apply deps/-main (map str args))))))
[& args]
(let [{:keys [cmd opts prev]} (p/parse-args args)
opts (merge {:in :inherit
:out :inherit
:err :inherit
:shutdown p/destroy-tree}
opts)]
(binding [*in* @sci/in
*out* @sci/out
*err* @sci/err
deps/*dir* (:dir opts)
deps/*env* (:env opts)
deps/*extra-env* (:extra-env opts)
deps/*process-fn* (fn
([cmd] (pp/process* {:cmd cmd
:prev prev
:opts opts}))
([cmd _] (pp/process* {:cmd cmd
:prev prev
:opts opts})))
deps/*exit-fn* (fn
([_])
([_exit-code msg]
(throw (Exception. msg))))]
(apply deps/-main cmd))))

View file

@ -66,6 +66,14 @@ true
(-> (babashka.deps/clojure [\"-M\" \"-e\" \"(+ 1 2 3)\"] {:out :string})
(p/check)
:out)
"))))
(is (= "6\n" (test-utils/normalize (bb "
(require '[babashka.deps :as deps])
(require '[babashka.process :as p])
(-> (babashka.deps/clojure {:out :string} \"-M\" \"-e\" \"(+ 1 2 3)\")
(p/check)
:out)
"))))
(when-not test-utils/native?
(is (thrown-with-msg? Exception #"Option changed" (bb "