[#829] Allow thread-first in combination with shell

This commit is contained in:
Michiel Borkent 2021-05-13 13:10:56 +02:00 committed by GitHub
parent 11b066ae70
commit 6aca41a48a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 5 deletions

@ -1 +1 @@
Subproject commit eba04e6c35814296e5bb383804f801aee912cba1 Subproject commit 3559a70686e435504b1bed320d2e513c5bf2bb15

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
BABASHKA_FEATURE_JDBC=true export BABASHKA_FEATURE_JDBC=true
BABASHKA_FEATURE_POSTGRESQL=true export BABASHKA_FEATURE_POSTGRESQL=true
lein test :only babashka.postgresql-test lein test :only babashka.postgresql-test

View file

@ -61,7 +61,12 @@
:shutdown p/destroy-tree}) :shutdown p/destroy-tree})
(defn shell [cmd & args] (defn shell [cmd & args]
(let [[opts cmd args] (let [[prev cmd args]
(if (and (map? cmd)
(:proc cmd))
[cmd (first args) (rest args)]
[nil cmd args])
[opts cmd args]
(if (map? cmd) (if (map? cmd)
[cmd (first args) (rest args)] [cmd (first args) (rest args)]
[nil cmd args]) [nil cmd args])
@ -75,6 +80,9 @@
(update opts :err io/file) (update opts :err io/file)
opts) opts)
opts) opts)
opts (if prev
(assoc opts :in nil)
opts)
cmd (if (.exists (io/file cmd)) cmd (if (.exists (io/file cmd))
[cmd] [cmd]
(p/tokenize cmd)) (p/tokenize cmd))
@ -82,7 +90,7 @@
local-log-level (:log-level opts)] local-log-level (:log-level opts)]
(sci/binding [log-level (or local-log-level @log-level)] (sci/binding [log-level (or local-log-level @log-level)]
(apply log-info cmd) (apply log-info cmd)
(handle-non-zero (p/process cmd (merge default-opts opts)) opts)))) (handle-non-zero (p/process prev cmd (merge default-opts opts)) opts))))
(defn clojure [cmd & args] (defn clojure [cmd & args]
(let [[opts cmd args] (let [[opts cmd args]

View file

@ -196,6 +196,13 @@
(test-utils/with-config '{:tasks {b (System/getProperty "babashka.task")}} (test-utils/with-config '{:tasks {b (System/getProperty "babashka.task")}}
(let [s (bb "run" "--prn" "b")] (let [s (bb "run" "--prn" "b")]
(is (= "b" s))))) (is (= "b" s)))))
(testing "shell pipe test"
(test-utils/with-config '{:tasks {a (-> (shell {:out :string}
"echo hello")
(shell {:out :string} "cat")
:out)}}
(let [s (bb "run" "--prn" "a")]
(is (= "hello\n" s)))))
(deftest list-tasks-test (deftest list-tasks-test
(test-utils/with-config {} (test-utils/with-config {}