This commit is contained in:
Michiel Borkent 2021-03-16 17:38:50 +01:00
parent d99f813fe8
commit 4d77ee6446

View file

@ -471,7 +471,7 @@ Use -- to separate script command line args from bb command line args.
(assoc opts-map :main (first options))))
(":do")
(let [options (next options)
options (into [] (comp (partition-by #(= % ","))
options (into [] (comp (partition-by #(= % ":do"))
(take-nth 2))
options)
parsed (map parse-opts options)]
@ -509,8 +509,9 @@ Use -- to separate script command line args from bb command line args.
;; this is for invoking babashka itself with command-line-args
(cond cmd-line-args
(parse-opts (seq (map str (concat cmd-line-args command-line-args))))
proc (do (-> proc (p/process {:inherit true}) p/check)
{:exit-code 0})))
proc {:exec (fn []
(-> proc (p/process {:inherit true}) p/check)
0)}))
(error (str "No such task: " task) 1)))
(error (str "File does not exist: " task) 1))))
@ -519,6 +520,8 @@ Use -- to separate script command line args from bb command line args.
(sci/binding [reflection-var false
core/data-readers @core/data-readers
sci/ns @sci/ns]
(if-let [f (:exec opts)]
(f)
(let [{version-opt :version
:keys [:shell-in :edn-in :shell-out :edn-out
:help? :file :command-line-args
@ -526,8 +529,7 @@ Use -- to separate script command line args from bb command line args.
:repl :socket-repl :nrepl
:verbose? :classpath
:main :uberscript :describe?
:jar :uberjar :clojure
:exit-code] :as opts}
:jar :uberjar :clojure] :as opts}
opts
_ (when clojure
(if-let [proc (deps/clojure (:opts opts))]
@ -613,7 +615,6 @@ Use -- to separate script command line args from bb command line args.
_ (vreset! common/ctx sci-ctx)
preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim))
[expressions exit-code]
(if exit-code [nil exit-code]
(cond expressions [expressions nil]
main [[(format "(ns user (:require [%1$s])) (apply %1$s/-main *command-line-args*)"
main)] nil]
@ -622,7 +623,7 @@ Use -- to separate script command line args from bb command line args.
(error-handler e {:expression expressions
:verbose? verbose?
:preloads preloads
:loader (:loader @cp/cp-state)})))))
:loader (:loader @cp/cp-state)}))))
expression (str/join " " expressions) ;; this might mess with the locations...
exit-code
;; handle preloads
@ -698,7 +699,7 @@ Use -- to separate script command line args from bb command line args.
:classpath classpath
:main-class main
:verbose verbose?}))
exit-code))))
exit-code)))))
(defn main [& args]
(let [opts (parse-opts args)]