diff --git a/src/babashka/impl/tasks.clj b/src/babashka/impl/tasks.clj index 302a59df..2f1619f5 100644 --- a/src/babashka/impl/tasks.clj +++ b/src/babashka/impl/tasks.clj @@ -28,11 +28,15 @@ (binding [*out* *err*] (println (format "[bb %s]" @task-name) (str/join " " strs)))))) -(defn- exit-non-zero [proc] - (when-let [exit-code (some-> proc deref :exit)] - (when (not (zero? exit-code)) - (log-error "Terminating bb with non-zero exit code: " exit-code) - (System/exit exit-code)))) +(defn- handle-non-zero [proc opts] + (when-let [proc (when proc (deref proc))] + (let [exit-code (:exit proc)] + (if (and (not (zero? exit-code)) + (not (:continue opts))) + (do (log-error "Terminating with non-zero exit code: " exit-code) + (System/exit exit-code)) + (with-meta proc + {:babashka/no-print true}))))) (def default-opts {:in :inherit @@ -50,6 +54,11 @@ (update opts :out io/file) opts) opts) + opts (if-let [o (:err opts)] + (if (string? o) + (update opts :err io/file) + opts) + opts) cmd (if (.exists (io/file cmd)) [cmd] (p/tokenize cmd)) @@ -57,7 +66,7 @@ local-log-level (:log-level opts)] (sci/binding [log-level (or local-log-level @log-level)] (apply log-info cmd) - (exit-non-zero (p/process cmd (merge default-opts opts)))))) + (handle-non-zero (p/process cmd (merge default-opts opts)) opts)))) (defn clojure [cmd & args] (let [[opts cmd args] @@ -69,6 +78,11 @@ (update opts :out io/file) opts) opts) + opts (if-let [o (:err opts)] + (if (string? o) + (update opts :err io/file) + opts) + opts) cmd (if (.exists (io/file cmd)) [cmd] (p/tokenize cmd)) @@ -76,7 +90,7 @@ local-log-level (:log-level opts)] (sci/binding [log-level (or local-log-level @log-level)] (apply log-info cmd) - (exit-non-zero (deps/clojure cmd (merge default-opts opts)))))) + (handle-non-zero (deps/clojure cmd (merge default-opts opts)) opts)))) (defn -wait [res] (when res diff --git a/src/babashka/main.clj b/src/babashka/main.clj index e5f64d74..28acd763 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -748,7 +748,9 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") input-var in core/command-line-args command-line-args] (sci/eval-string* sci-ctx expression))] - (when (some? res) + ;; return value printing + (when (and (some? res) + (not (:babashka/no-print (meta res)))) (if-let [pr-f (cond shell-out println edn-out prn)] (if (coll? res) diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 81c8b37f..93417f10 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -45,6 +45,14 @@ "echo hello")}} (bb "foo") (is (= "hello\n" (slurp out))))) + (testing "shell test with :continue" + (test-utils/with-config {:tasks {'foo (list 'shell {:out out + :err out + :continue true} + "ls foobar")}} + (bb "foo") + (is (str/includes? (slurp out) + "foobar")))) (fs/delete out) (testing "clojure test" (test-utils/with-config {:tasks {'foo (list 'clojure {:out out}