diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 6a18b58a..880966c2 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -844,6 +844,18 @@ Use -- to separate script command line args from bb command line args. :verbose verbose?})) exit-code)))) +(defn exec* [opts] + (if-let [do-opts (:do opts)] + (reduce (fn [prev-exit opts] + ;; (prn :prev prev-exit) + ;; (prn :opts opts) + (if (pos? prev-exit) + (reduced prev-exit) + (exec* opts))) + 0 + do-opts) + (exec opts))) + (defn main [& args] (let [bb-edn-file (or (System/getenv "BABASHKA_EDN") "bb.edn")] @@ -853,16 +865,7 @@ Use -- to separate script command line args from bb command line args. ;; we mutate the atom from tests as well, so despite the above it can contain a bb.edn (when-let [bb-edn @bb-edn] (deps/add-deps bb-edn))) (let [opts (parse-opts args)] - (if-let [do-opts (:do opts)] - (reduce (fn [prev-exit opts] - ;; (prn :prev prev-exit) - ;; (prn :opts opts) - (if (pos? prev-exit) - (reduced prev-exit) - (exec opts))) - 0 - do-opts) - (exec opts)))) + (exec* opts))) (defn -main [& args] diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 3d3f9619..490f7528 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -151,3 +151,16 @@ Addition is a pretty advanced topic. Let us start with the identity element (let [res (apply test-utils/bb nil (map str ["doc" :main-task]))] (is (str/includes? res "Usage: just pass some args"))))) + +(deftest do-test + (let [temp-dir (fs/create-temp-dir) + temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))] + (with-config {:tasks {:bye ['do + ['babashka "-e" "(+ 1 2 3)"] + ['shell "rm" (str temp-file)]] + :hello ['do + ['babashka "-e" "(+ 1 2 3)"] + [:bye]]}} + (is (fs/exists? temp-file)) + (bb :hello) + (is (not (fs/exists? temp-file))))))