Skip to content

Commit aa0a43e

Browse files
authored
Fix #124: allow passing cmd inside map (#109)
1 parent 748b098 commit aa0a43e

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
[Babashka process](https://github.com/babashka/process)
44
Clojure library for shelling out / spawning sub-processes
55

6+
## 0.5.19 (2023-05-11)
7+
8+
- #124: Allow `:cmd` to be passed in map argument
9+
610
## 0.5.18
711

812
- 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
2529

2630
- Auto-load `babashka.process.pprint` if `clojure.pprint` was already loaded
2731

28-
## 0.4.13
32+
## 0.4.13 (2022-12-04)
2933

3034
- Fix invocation with file argument
3135

src/babashka/process.cljc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,10 @@
308308
[fst]
309309
(if fst
310310
(tokenize fst)
311-
fst)) rst)))]
311+
fst)) rst)))
312+
prev (:prev opts prev)]
312313
{:prev prev
313-
:cmd args
314+
:cmd (or (:cmd opts) args)
314315
:opts opts}))
315316

316317
(defn pb
@@ -412,9 +413,11 @@
412413
the exit code.
413414
414415
Supported options:
416+
- `:cmd`: a vector of strings. A single string can be tokenized into a vector of strings with `tokenize`.
417+
Overrides the variadic `args` argument.
415418
- `:in`, `:out`, `:err`: objects compatible with `clojure.java.io/copy` that
416-
will be copied to or from the process's corresponding stream. May be set
417-
to `:inherit` for redirecting to the parent process's corresponding
419+
will be copied to from the process's corresponding stream.
420+
May be set to `:inherit` for redirecting to the parent process's corresponding
418421
stream. Optional `:in-enc`, `:out-enc` and `:err-enc` values will
419422
be passed along to `clojure.java.io/copy`.
420423
For redirecting to Clojure's `*in*`, `*out*` or `*err*` stream, set
@@ -426,6 +429,7 @@
426429
For writing output to a file, you can set `:out` and `:err` to a `java.io.File` object, or a keyword:
427430
- `:write` + an additional `:out-file`/`:err-file` + file to write to the file.
428431
- `:append` + an additional `:out-file`/`:err-file` + file to append to the file.
432+
- `:prev`: output from `:prev` will be piped to the input of this process. Overrides `:in`.
429433
- `:inherit`: if true, sets `:in`, `:out` and `:err` to `:inherit`.
430434
- `:dir`: working directory.
431435
- `:env`, `:extra-env`: a map of environment variables. See [Add environment](/README.md#add-environment).

test/babashka/process_test.cljc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@
113113
(let [args ["README.md" "a" "b" "c"]]
114114
(is (= args (:cmd (p/parse-args args))))))
115115
(testing "prev may be nil"
116-
(is (= ["echo" "hello"] (:cmd (p/parse-args [nil ["echo hello"]])))))))
116+
(is (= ["echo" "hello"] (:cmd (p/parse-args [nil ["echo hello"]])))))
117+
(testing "cmd + prev"
118+
(let [parsed (p/parse-args [{:cmd ["echo" "hello"]
119+
:prev @(process {:out :string} "ls")}])]
120+
(is (= ["echo" "hello"] (:cmd parsed)))
121+
(is (string? (:out (:prev parsed))))))))
117122

118123
(deftest process-wait-realize-test
119124
(testing "By default process returns string out and err, returning the exit

0 commit comments

Comments
 (0)