Foo
This commit is contained in:
parent
18219526e2
commit
23834a5302
3 changed files with 22 additions and 15 deletions
|
|
@ -5,8 +5,12 @@
|
||||||
|
|
||||||
(declare resolve-task)
|
(declare resolve-task)
|
||||||
|
|
||||||
|
(defn error [msg exit]
|
||||||
|
(binding [*out* *err*]
|
||||||
|
(println msg)
|
||||||
|
{:exit-code exit}))
|
||||||
|
|
||||||
(defn parse-opts [options]
|
(defn parse-opts [options]
|
||||||
(prn :options options)
|
|
||||||
(let [opts (loop [options options
|
(let [opts (loop [options options
|
||||||
opts-map {}]
|
opts-map {}]
|
||||||
(if options
|
(if options
|
||||||
|
|
@ -129,7 +133,7 @@
|
||||||
:command-line-args (next options))
|
:command-line-args (next options))
|
||||||
(if (str/starts-with? opt ":")
|
(if (str/starts-with? opt ":")
|
||||||
(resolve-task opt {:command-line-args (next options)})
|
(resolve-task opt {:command-line-args (next options)})
|
||||||
(throw (Exception. (str "File does not exist: " opt))))))))))
|
(error (str "File does not exist: " opt) 1))))))))
|
||||||
opts-map))]
|
opts-map))]
|
||||||
opts))
|
opts))
|
||||||
|
|
||||||
|
|
@ -142,5 +146,5 @@
|
||||||
(let [cmd-line-args (get task :babashka/args)]
|
(let [cmd-line-args (get task :babashka/args)]
|
||||||
;; this is for invoking babashka itself with command-line-args
|
;; this is for invoking babashka itself with command-line-args
|
||||||
(parse-opts (seq (concat cmd-line-args command-line-args))))
|
(parse-opts (seq (concat cmd-line-args command-line-args))))
|
||||||
(throw (Exception. (str "No such task: " task)))))
|
(error (str "No such task: " task) 1)))
|
||||||
(throw (Exception. (str "File does not exist: " task))))))
|
(error (str "File does not exist: " task) 1))))
|
||||||
|
|
|
||||||
|
|
@ -371,7 +371,8 @@ Use -- to separate script command line args from bb command line args.
|
||||||
:repl :socket-repl :nrepl
|
:repl :socket-repl :nrepl
|
||||||
:verbose? :classpath
|
:verbose? :classpath
|
||||||
:main :uberscript :describe?
|
:main :uberscript :describe?
|
||||||
:jar :uberjar :clojure :task] :as opts}
|
:jar :uberjar :clojure :task
|
||||||
|
:exit-code] :as opts}
|
||||||
(cli/parse-opts args)
|
(cli/parse-opts args)
|
||||||
_ (when clojure
|
_ (when clojure
|
||||||
(if-let [proc (deps/clojure (:opts opts))]
|
(if-let [proc (deps/clojure (:opts opts))]
|
||||||
|
|
@ -457,15 +458,16 @@ Use -- to separate script command line args from bb command line args.
|
||||||
_ (vreset! common/ctx sci-ctx)
|
_ (vreset! common/ctx sci-ctx)
|
||||||
preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim))
|
preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim))
|
||||||
[expressions exit-code]
|
[expressions exit-code]
|
||||||
(cond expressions [expressions nil]
|
(if exit-code [nil exit-code]
|
||||||
main [[(format "(ns user (:require [%1$s])) (apply %1$s/-main *command-line-args*)"
|
(cond expressions [expressions nil]
|
||||||
main)] nil]
|
main [[(format "(ns user (:require [%1$s])) (apply %1$s/-main *command-line-args*)"
|
||||||
file (try [[(read-file file)] nil]
|
main)] nil]
|
||||||
(catch Exception e
|
file (try [[(read-file file)] nil]
|
||||||
(error-handler e {:expression expressions
|
(catch Exception e
|
||||||
:verbose? verbose?
|
(error-handler e {:expression expressions
|
||||||
:preloads preloads
|
:verbose? verbose?
|
||||||
:loader (:loader @cp/cp-state)}))))
|
:preloads preloads
|
||||||
|
:loader (:loader @cp/cp-state)})))))
|
||||||
expression (str/join " " expressions) ;; this might mess with the locations...
|
expression (str/join " " expressions) ;; this might mess with the locations...
|
||||||
exit-code
|
exit-code
|
||||||
;; handle preloads
|
;; handle preloads
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
{:tasks {:eval-plus {:babashka/args ["-e" "(+ 1 2 3)"]}}}
|
{:tasks {:eval-plus {:babashka/args ["-e" "(+ 1 2 3)"]}
|
||||||
|
:tree {:babashka/args [":clojure" "-Stree"]}}}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue