Skip to content

Commit

Permalink
Fix #124: allow passing cmd inside map (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored May 11, 2023
1 parent 748b098 commit aa0a43e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
12 changes: 8 additions & 4 deletions src/babashka/process.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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).
Expand Down
7 changes: 6 additions & 1 deletion test/babashka/process_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aa0a43e

Please sign in to comment.