wip [skip ci]
This commit is contained in:
parent
40e7b739e9
commit
60e25043d4
4 changed files with 14 additions and 13 deletions
|
|
@ -20,6 +20,8 @@
|
||||||
ret#))
|
ret#))
|
||||||
|
|
||||||
(def data-readers (sci/new-dynamic-var '*data-readers* nil))
|
(def data-readers (sci/new-dynamic-var '*data-readers* nil))
|
||||||
|
(def command-line-args (sci/new-dynamic-var '*command-line-args* nil))
|
||||||
|
(def warn-on-reflection (sci/new-dynamic-var '*warn-on-reflection* false))
|
||||||
|
|
||||||
(defn read+string
|
(defn read+string
|
||||||
"Added for compatibility. Must be used with
|
"Added for compatibility. Must be used with
|
||||||
|
|
@ -59,4 +61,6 @@
|
||||||
'default-data-readers default-data-readers
|
'default-data-readers default-data-readers
|
||||||
'xml-seq (copy-core-var xml-seq)
|
'xml-seq (copy-core-var xml-seq)
|
||||||
'read+string (fn [& args]
|
'read+string (fn [& args]
|
||||||
(apply read+string @common/ctx args))})
|
(apply read+string @common/ctx args))
|
||||||
|
'*command-line-args* command-line-args
|
||||||
|
'*warn-on-reflection* warn-on-reflection})
|
||||||
|
|
|
||||||
|
|
@ -181,8 +181,6 @@ Use -- to separate script command line args from bb command line args.
|
||||||
(str/replace x #"^#!.*" ""))
|
(str/replace x #"^#!.*" ""))
|
||||||
(throw (Exception. (str "File does not exist: " file))))))
|
(throw (Exception. (str "File does not exist: " file))))))
|
||||||
|
|
||||||
(def reflection-var (sci/new-dynamic-var '*warn-on-reflection* false))
|
|
||||||
|
|
||||||
(defn load-file* [f]
|
(defn load-file* [f]
|
||||||
(let [f (io/file f)
|
(let [f (io/file f)
|
||||||
s (slurp f)]
|
s (slurp f)]
|
||||||
|
|
@ -199,7 +197,7 @@ Use -- to separate script command line args from bb command line args.
|
||||||
nrepl-opts (assoc nrepl-opts
|
nrepl-opts (assoc nrepl-opts
|
||||||
:debug dev?
|
:debug dev?
|
||||||
:describe {"versions" {"babashka" version}}
|
:describe {"versions" {"babashka" version}}
|
||||||
:thread-bind [reflection-var])]
|
:thread-bind [core/warn-on-reflection])]
|
||||||
(nrepl-server/start-server! ctx nrepl-opts)
|
(nrepl-server/start-server! ctx nrepl-opts)
|
||||||
(binding [*out* *err*]
|
(binding [*out* *err*]
|
||||||
(println "For more info visit: https://book.babashka.org/#_nrepl")))
|
(println "For more info visit: https://book.babashka.org/#_nrepl")))
|
||||||
|
|
@ -539,7 +537,7 @@ Use -- to separate script command line args from bb command line args.
|
||||||
|
|
||||||
(defn exec [opts]
|
(defn exec [opts]
|
||||||
(binding [*unrestricted* true]
|
(binding [*unrestricted* true]
|
||||||
(sci/binding [reflection-var false
|
(sci/binding [core/warn-on-reflection @core/warn-on-reflection
|
||||||
core/data-readers @core/data-readers
|
core/data-readers @core/data-readers
|
||||||
sci/ns @sci/ns]
|
sci/ns @sci/ns]
|
||||||
(let [{version-opt :version
|
(let [{version-opt :version
|
||||||
|
|
@ -600,15 +598,11 @@ Use -- to separate script command line args from bb command line args.
|
||||||
["META-INF/MANIFEST.MF"] {:url? true})]
|
["META-INF/MANIFEST.MF"] {:url? true})]
|
||||||
(cp/main-ns res))
|
(cp/main-ns res))
|
||||||
main)
|
main)
|
||||||
|
|
||||||
;; TODO: pull more of these values to compile time
|
;; TODO: pull more of these values to compile time
|
||||||
opts {:aliases aliases
|
opts {:aliases aliases
|
||||||
:namespaces (-> namespaces
|
:namespaces (-> namespaces
|
||||||
(assoc 'clojure.core
|
(assoc 'clojure.core
|
||||||
(assoc core-extras
|
(assoc core-extras
|
||||||
'*command-line-args*
|
|
||||||
(sci/new-dynamic-var '*command-line-args* command-line-args)
|
|
||||||
'*warn-on-reflection* reflection-var
|
|
||||||
'load-file load-file*))
|
'load-file load-file*))
|
||||||
(assoc-in ['clojure.java.io 'resource]
|
(assoc-in ['clojure.java.io 'resource]
|
||||||
(fn [path]
|
(fn [path]
|
||||||
|
|
@ -693,7 +687,8 @@ Use -- to separate script command line args from bb command line args.
|
||||||
[nil 0] ;; done streaming
|
[nil 0] ;; done streaming
|
||||||
(let [res [(let [res
|
(let [res [(let [res
|
||||||
(sci/binding [sci/file (or @sci/file "<expr>")
|
(sci/binding [sci/file (or @sci/file "<expr>")
|
||||||
input-var in]
|
input-var in
|
||||||
|
core/command-line-args command-line-args]
|
||||||
(sci/eval-string* sci-ctx expression))]
|
(sci/eval-string* sci-ctx expression))]
|
||||||
(when (some? res)
|
(when (some? res)
|
||||||
(if-let [pr-f (cond shell-out println
|
(if-let [pr-f (cond shell-out println
|
||||||
|
|
@ -742,7 +737,6 @@ Use -- to separate script command line args from bb command line args.
|
||||||
(let [opts (parse-opts args)]
|
(let [opts (parse-opts args)]
|
||||||
(if-let [do-opts (:do opts)]
|
(if-let [do-opts (:do opts)]
|
||||||
(reduce (fn [_ opts]
|
(reduce (fn [_ opts]
|
||||||
;; (prn :opts opts)
|
|
||||||
(let [ret (exec opts)]
|
(let [ret (exec opts)]
|
||||||
(if (pos? ret)
|
(if (pos? ret)
|
||||||
(reduced ret)
|
(reduced ret)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]))
|
||||||
|
|
||||||
(defn bash [& args]
|
(defn bash [& args]
|
||||||
(prn :args args)
|
;; (prn :args args)
|
||||||
(prn :cmd *command-line-args*)
|
;; (prn :cmd *command-line-args*)
|
||||||
(-> (p/process ["bash" "-c" (str/join " " args)]
|
(-> (p/process ["bash" "-c" (str/join " " args)]
|
||||||
{:inherit true})
|
{:inherit true})
|
||||||
p/check))
|
p/check))
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@
|
||||||
*command-line-args*))]}
|
*command-line-args*))]}
|
||||||
:tree {:task/type :babashka
|
:tree {:task/type :babashka
|
||||||
:args [:clojure -Stree]}
|
:args [:clojure -Stree]}
|
||||||
|
:do-bash {:task/type :babashka
|
||||||
|
:args [:do :bash "ls | wc -l"
|
||||||
|
:__ :eval-plus 1 2 3]}
|
||||||
:all {:task/type :babashka
|
:all {:task/type :babashka
|
||||||
:args [:do :count-files
|
:args [:do :count-files
|
||||||
:__ :bash "ls | wc -l"
|
:__ :bash "ls | wc -l"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue