[#371] fix arg parsing

This commit is contained in:
Michiel Borkent 2020-04-21 15:08:20 +02:00
parent f2b7aaaaea
commit 045226ac54
2 changed files with 25 additions and 9 deletions

View file

@ -22,8 +22,8 @@
[babashka.impl.socket-repl :as socket-repl]
[babashka.impl.test :as t]
[babashka.impl.tools.cli :refer [tools-cli-namespace]]
[babashka.impl.xml :as xml]
[babashka.impl.transit :refer [transit-namespace]]
[babashka.impl.xml :as xml]
[babashka.impl.yaml :refer [yaml-namespace]]
[babashka.wait :as wait]
[clojure.edn :as edn]
@ -115,17 +115,25 @@
(assoc opts-map
:repl true)))
("--socket-repl")
(let [options (next options)]
(recur (next options)
(let [options (next options)
opt (first options)
opt (when-not (str/starts-with? opt "-")
opt)
options (if opt (next options)
options)]
(recur options
(assoc opts-map
:socket-repl (or (first options)
"1666"))))
:socket-repl (or opt "1666"))))
("--nrepl-server")
(let [options (next options)]
(recur (next options)
(let [options (next options)
opt (first options)
opt (when-not (str/starts-with? opt "-")
opt)
options (if opt (next options)
options)]
(recur options
(assoc opts-map
:nrepl (or (first options)
"1667"))))
:nrepl (or opt "1667"))))
("--eval", "-e")
(let [options (next options)]
(recur (next options)

View file

@ -17,6 +17,14 @@
(edn/read-string (apply test-utils/bb (when (some? input) (str input)) (map str args))))
(deftest parse-opts-test
(is (= {:nrepl "1667", :classpath "src"}
(main/parse-opts ["--nrepl-server" "-cp" "src"])))
(is (= {:socket-repl "1666", :expressions ["123"]}
(main/parse-opts ["--socket-repl" "-e" "123"])))
(is (= {:socket-repl "1666", :expressions ["123"]}
(main/parse-opts ["--socket-repl" "1666" "-e" "123"])))
(is (= {:nrepl "1666", :expressions ["123"]}
(main/parse-opts ["--nrepl-server" "1666" "-e" "123"])))
(is (= 123 (bb nil "(println 123)")))
(is (= 123 (bb nil "-e" "(println 123)")))
(is (= 123 (bb nil "--eval" "(println 123)")))