[#35] make -i option lazy
This commit is contained in:
parent
da4714b5dd
commit
8e26cefc0c
2 changed files with 12 additions and 7 deletions
|
|
@ -54,8 +54,8 @@
|
|||
opts-map))]
|
||||
opts))
|
||||
|
||||
(defn parse-shell-string [s]
|
||||
(str/split s #"\n"))
|
||||
(defn parse-shell-string [in]
|
||||
(line-seq (java.io.BufferedReader. in)))
|
||||
|
||||
(defn print-version []
|
||||
(println (str "babashka v"(str/trim (slurp (io/resource "BABASHKA_VERSION"))))))
|
||||
|
|
@ -164,10 +164,9 @@
|
|||
(if stream?
|
||||
(if raw-in (or (read-line) ::EOF)
|
||||
(read-edn))
|
||||
(delay (let [in (slurp *in*)]
|
||||
(if raw-in
|
||||
(parse-shell-string in)
|
||||
(edn/read-string in))))))
|
||||
(delay (if raw-in
|
||||
(parse-shell-string *in*)
|
||||
(edn/read *in*)))))
|
||||
env (atom {})
|
||||
ctx {:bindings (assoc bindings '*command-line-args* command-line-args)
|
||||
:env env}
|
||||
|
|
|
|||
|
|
@ -123,4 +123,10 @@
|
|||
head -n10"))
|
||||
out (str/split-lines out)
|
||||
out (map edn/read-string out)]
|
||||
(is (= out (take 10 (map #(* % %) (range))))))))
|
||||
(is (= (take 10 (map #(* % %) (range))) out)))))
|
||||
|
||||
(deftest lazy-text-in-test
|
||||
(when test-utils/native?
|
||||
(let [out (:out (sh "bash" "-c" "yes | ./bb -i '(take 2 *in*)'"))
|
||||
out (edn/read-string out)]
|
||||
(is (= '("y" "y") out)))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue