[#213] Allow -e argument to be repeated
This commit is contained in:
parent
8f698894f6
commit
a442bde76a
2 changed files with 14 additions and 12 deletions
|
|
@ -99,21 +99,21 @@
|
|||
("--eval", "-e")
|
||||
(let [options (next options)]
|
||||
(recur (next options)
|
||||
(assoc opts-map :expression (first options))))
|
||||
(update opts-map :expressions (fnil conj []) (first options))))
|
||||
("--main", "-m")
|
||||
(let [options (next options)]
|
||||
(recur (next options)
|
||||
(assoc opts-map :main (first options))))
|
||||
(if (some opts-map [:file :socket-repl :expression :main])
|
||||
(if (some opts-map [:file :socket-repl :expressions :main])
|
||||
(assoc opts-map
|
||||
:command-line-args options)
|
||||
(let [trimmed-opt (str/triml opt)
|
||||
c (.charAt trimmed-opt 0)]
|
||||
(case c
|
||||
(\( \{ \[ \* \@ \#)
|
||||
(assoc opts-map
|
||||
:expression opt
|
||||
:command-line-args (next options))
|
||||
(-> opts-map
|
||||
(update :expressions (fnil conj []) (first options))
|
||||
(assoc :command-line-args (next options)))
|
||||
(assoc opts-map
|
||||
:file opt
|
||||
:command-line-args (next options)))))))
|
||||
|
|
@ -274,7 +274,7 @@ Everything after that is bound to *command-line-args*."))
|
|||
(let [t0 (System/currentTimeMillis)
|
||||
{:keys [:version :shell-in :edn-in :shell-out :edn-out
|
||||
:help? :file :command-line-args
|
||||
:expression :stream? :time?
|
||||
:expressions :stream? :time?
|
||||
:repl :socket-repl
|
||||
:verbose? :classpath
|
||||
:main :uberscript] :as _opts}
|
||||
|
|
@ -348,13 +348,14 @@ Everything after that is bound to *command-line-args*."))
|
|||
(let [opts (apply hash-map opts)]
|
||||
(repl/start-repl! sci-ctx opts))))))
|
||||
preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim))
|
||||
[expression exit-code]
|
||||
(cond expression [expression nil]
|
||||
main [(format "(ns user (:require [%1$s])) (apply %1$s/-main *command-line-args*)"
|
||||
main) nil]
|
||||
file (try [(read-file file) nil]
|
||||
[expressions exit-code]
|
||||
(cond expressions [expressions nil]
|
||||
main [[(format "(ns user (:require [%1$s])) (apply %1$s/-main *command-line-args*)"
|
||||
main)] nil]
|
||||
file (try [[(read-file file)] nil]
|
||||
(catch Exception e
|
||||
(error-handler* e verbose?))))
|
||||
expression (str/join " " expressions) ;; this might mess with the locations...
|
||||
exit-code
|
||||
;; handle preloads
|
||||
(if exit-code exit-code
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
(testing "distinguish automatically between expression or file name"
|
||||
(is (= {:result 8080} (bb nil "test/babashka/scripts/tools.cli.bb")))
|
||||
(is (thrown-with-msg? Exception #"does not exist" (bb nil "foo.clj")))
|
||||
(is (thrown-with-msg? Exception #"does not exist" (bb nil "-help")))))
|
||||
(is (thrown-with-msg? Exception #"does not exist" (bb nil "-help"))))
|
||||
(is (= "1 2 3" (bb nil "-e" "(require '[clojure.string :as str1])" "-e" "(str1/join \" \" [1 2 3])"))))
|
||||
|
||||
(deftest print-error-test
|
||||
(is (thrown-with-msg? Exception #"java.lang.NullPointerException"
|
||||
|
|
|
|||
Loading…
Reference in a new issue