From aa0a43e38b8a9533171418f8c1f1051a7d3a38fc Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 11 May 2023 23:19:38 +0200 Subject: [PATCH] Fix #124: allow passing cmd inside map (#109) --- CHANGELOG.md | 6 +++++- src/babashka/process.cljc | 12 ++++++++---- test/babashka/process_test.cljc | 7 ++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4eef2f..4ee0fa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ [Babashka process](https://github.com/babashka/process) Clojure library for shelling out / spawning sub-processes +## 0.5.19 (2023-05-11) + +- #124: Allow `:cmd` to be passed in map argument + ## 0.5.18 - Fix regression introduced in #112: `exec` always needs to resolve the full path of the program @@ -25,7 +29,7 @@ Clojure library for shelling out / spawning sub-processes - Auto-load `babashka.process.pprint` if `clojure.pprint` was already loaded -## 0.4.13 +## 0.4.13 (2022-12-04) - Fix invocation with file argument diff --git a/src/babashka/process.cljc b/src/babashka/process.cljc index 1dd05c0..f3b8e46 100644 --- a/src/babashka/process.cljc +++ b/src/babashka/process.cljc @@ -308,9 +308,10 @@ [fst] (if fst (tokenize fst) - fst)) rst)))] + fst)) rst))) + prev (:prev opts prev)] {:prev prev - :cmd args + :cmd (or (:cmd opts) args) :opts opts})) (defn pb @@ -412,9 +413,11 @@ the exit code. Supported options: + - `:cmd`: a vector of strings. A single string can be tokenized into a vector of strings with `tokenize`. + Overrides the variadic `args` argument. - `:in`, `:out`, `:err`: objects compatible with `clojure.java.io/copy` that - will be copied to or from the process's corresponding stream. May be set - to `:inherit` for redirecting to the parent process's corresponding + will be copied to from the process's corresponding stream. + May be set to `:inherit` for redirecting to the parent process's corresponding stream. Optional `:in-enc`, `:out-enc` and `:err-enc` values will be passed along to `clojure.java.io/copy`. For redirecting to Clojure's `*in*`, `*out*` or `*err*` stream, set @@ -426,6 +429,7 @@ For writing output to a file, you can set `:out` and `:err` to a `java.io.File` object, or a keyword: - `:write` + an additional `:out-file`/`:err-file` + file to write to the file. - `:append` + an additional `:out-file`/`:err-file` + file to append to the file. + - `:prev`: output from `:prev` will be piped to the input of this process. Overrides `:in`. - `:inherit`: if true, sets `:in`, `:out` and `:err` to `:inherit`. - `:dir`: working directory. - `:env`, `:extra-env`: a map of environment variables. See [Add environment](/README.md#add-environment). diff --git a/test/babashka/process_test.cljc b/test/babashka/process_test.cljc index cebc4d7..3eae6ab 100644 --- a/test/babashka/process_test.cljc +++ b/test/babashka/process_test.cljc @@ -113,7 +113,12 @@ (let [args ["README.md" "a" "b" "c"]] (is (= args (:cmd (p/parse-args args)))))) (testing "prev may be nil" - (is (= ["echo" "hello"] (:cmd (p/parse-args [nil ["echo hello"]]))))))) + (is (= ["echo" "hello"] (:cmd (p/parse-args [nil ["echo hello"]]))))) + (testing "cmd + prev" + (let [parsed (p/parse-args [{:cmd ["echo" "hello"] + :prev @(process {:out :string} "ls")}])] + (is (= ["echo" "hello"] (:cmd parsed))) + (is (string? (:out (:prev parsed)))))))) (deftest process-wait-realize-test (testing "By default process returns string out and err, returning the exit