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#))
|
||||
|
||||
(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
|
||||
"Added for compatibility. Must be used with
|
||||
|
|
@ -59,4 +61,6 @@
|
|||
'default-data-readers default-data-readers
|
||||
'xml-seq (copy-core-var xml-seq)
|
||||
'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 #"^#!.*" ""))
|
||||
(throw (Exception. (str "File does not exist: " file))))))
|
||||
|
||||
(def reflection-var (sci/new-dynamic-var '*warn-on-reflection* false))
|
||||
|
||||
(defn load-file* [f]
|
||||
(let [f (io/file 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
|
||||
:debug dev?
|
||||
:describe {"versions" {"babashka" version}}
|
||||
:thread-bind [reflection-var])]
|
||||
:thread-bind [core/warn-on-reflection])]
|
||||
(nrepl-server/start-server! ctx nrepl-opts)
|
||||
(binding [*out* *err*]
|
||||
(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]
|
||||
(binding [*unrestricted* true]
|
||||
(sci/binding [reflection-var false
|
||||
(sci/binding [core/warn-on-reflection @core/warn-on-reflection
|
||||
core/data-readers @core/data-readers
|
||||
sci/ns @sci/ns]
|
||||
(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})]
|
||||
(cp/main-ns res))
|
||||
main)
|
||||
|
||||
;; TODO: pull more of these values to compile time
|
||||
opts {:aliases aliases
|
||||
:namespaces (-> namespaces
|
||||
(assoc 'clojure.core
|
||||
(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*))
|
||||
(assoc-in ['clojure.java.io 'resource]
|
||||
(fn [path]
|
||||
|
|
@ -693,7 +687,8 @@ Use -- to separate script command line args from bb command line args.
|
|||
[nil 0] ;; done streaming
|
||||
(let [res [(let [res
|
||||
(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))]
|
||||
(when (some? res)
|
||||
(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)]
|
||||
(if-let [do-opts (:do opts)]
|
||||
(reduce (fn [_ opts]
|
||||
;; (prn :opts opts)
|
||||
(let [ret (exec opts)]
|
||||
(if (pos? ret)
|
||||
(reduced ret)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
[clojure.string :as str]))
|
||||
|
||||
(defn bash [& args]
|
||||
(prn :args args)
|
||||
(prn :cmd *command-line-args*)
|
||||
;; (prn :args args)
|
||||
;; (prn :cmd *command-line-args*)
|
||||
(-> (p/process ["bash" "-c" (str/join " " args)]
|
||||
{:inherit true})
|
||||
p/check))
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@
|
|||
*command-line-args*))]}
|
||||
:tree {:task/type :babashka
|
||||
:args [:clojure -Stree]}
|
||||
:do-bash {:task/type :babashka
|
||||
:args [:do :bash "ls | wc -l"
|
||||
:__ :eval-plus 1 2 3]}
|
||||
:all {:task/type :babashka
|
||||
:args [:do :count-files
|
||||
:__ :bash "ls | wc -l"
|
||||
|
|
|
|||
Loading…
Reference in a new issue