From 69db7105e5701fbb80f1567c2c59dd680c6935db Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Wed, 7 Dec 2022 10:04:40 +0100 Subject: [PATCH] Support new syntax in babashka.deps/clojure (#1440) --- src/babashka/deps.clj | 47 ++++++++++++++++++++----------------- test/babashka/deps_test.clj | 8 +++++++ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/babashka/deps.clj b/src/babashka/deps.clj index d37218f2..ea8daa59 100644 --- a/src/babashka/deps.clj +++ b/src/babashka/deps.clj @@ -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)))) diff --git a/test/babashka/deps_test.clj b/test/babashka/deps_test.clj index d3edade2..e130e680 100644 --- a/test/babashka/deps_test.clj +++ b/test/babashka/deps_test.clj @@ -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 "