Skip to content

Commit

Permalink
Fix CLJS
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Dec 19, 2023
1 parent 9a7a802 commit e331bcf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,9 @@
;; Either way, we need to print to stderr
(:no-match :input-exhausted)
(let [println (fn [& args]
#?(:cljs (apply *print-err-fn* args)
#?(:cljs (doseq [a args]
(*print-err-fn* a)
(*print-err-fn* "\n"))
:clj (binding [*out* *err*]
(apply println args))))]
(println (str "No matching command" (when wrong-input
Expand Down
15 changes: 8 additions & 7 deletions test/babashka/cli_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -297,20 +297,21 @@
:fn identity}]))))

(deftest dispatch-tree-test
(let [table [{:cmds ["foo" "bar"]
:spec {:baz {:coerce :boolean}}
:fn identity}
{:cmds ["foo" "bar" "baz"]
:spec {:quux {:coerce :keyword}}
:fn identity}]]
(d/deflet
(def table [{:cmds ["foo" "bar"]
:spec {:baz {:coerce :boolean}}
:fn identity}
{:cmds ["foo" "bar" "baz"]
:spec {:quux {:coerce :keyword}}
:fn identity}])
(is (= (str/split-lines "No matching command\nAvailable commands:\nfoo\n")
(str/split-lines (with-out-str
(binding #?(:clj [*err* *out*]
:cljs [*print-err-fn* *print-fn*
*print-newline* true])
(cli/dispatch table []))))))
#_#_(is (= (str/split-lines "No matching command\nAvailable commands:\nbar\n")
(str/split-lines (with-out-str (cli/dispatch table ["foo" "--baz" "quux"])))))
(str/split-lines (with-out-str (cli/dispatch table ["foo" "--baz" "quux"])))))
(is (= (str/split-lines "No matching command: baz\nAvailable commands:\nbar\n")
(str/split-lines (with-out-str (cli/dispatch table ["foo" "baz" "--baz" "quux"])))))
(is (= {:dispatch ["foo" "bar"], :opts {:baz true}, :args ["quux"]}
Expand Down

0 comments on commit e331bcf

Please sign in to comment.