wip [skip ci]
This commit is contained in:
parent
44f80f2a28
commit
afed99ad1b
3 changed files with 33 additions and 16 deletions
|
|
@ -515,8 +515,15 @@ Use -- to separate script command line args from bb command line args.
|
||||||
:shell
|
:shell
|
||||||
(let [args (get task :args)]
|
(let [args (get task :args)]
|
||||||
{:exec (fn []
|
{:exec (fn []
|
||||||
(p/process args {:inherit true}) p/check
|
(p/process args {:inherit true}) p/check)})
|
||||||
0)}))
|
:fn
|
||||||
|
(let [var (get task :var)
|
||||||
|
var-sym (symbol var)]
|
||||||
|
{:exec-src (pr-str `(do (if-let [f (requiring-resolve '~var-sym)]
|
||||||
|
(apply f *command-line-args*)
|
||||||
|
(throw (Exception. (str "Var not found: " '~var-sym
|
||||||
|
" " (babashka.classpath/get-classpath)))))))
|
||||||
|
:command-line-args command-line-args}))
|
||||||
(error (str "No such task: " task) 1))
|
(error (str "No such task: " task) 1))
|
||||||
(error (str "File does not exist: " task) 1)))
|
(error (str "File does not exist: " task) 1)))
|
||||||
|
|
||||||
|
|
@ -524,6 +531,8 @@ Use -- to separate script command line args from bb command line args.
|
||||||
"if true, then we should still load preloads and user.clj"
|
"if true, then we should still load preloads and user.clj"
|
||||||
(volatile! true))
|
(volatile! true))
|
||||||
|
|
||||||
|
(def env (atom {}))
|
||||||
|
|
||||||
(defn exec [opts]
|
(defn exec [opts]
|
||||||
(binding [*unrestricted* true]
|
(binding [*unrestricted* true]
|
||||||
(sci/binding [reflection-var false
|
(sci/binding [reflection-var false
|
||||||
|
|
@ -536,7 +545,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]
|
:jar :uberjar :clojure
|
||||||
|
:exec-src]
|
||||||
exec-fn :exec}
|
exec-fn :exec}
|
||||||
opts
|
opts
|
||||||
_ (when verbose? (vreset! common/verbose? true))
|
_ (when verbose? (vreset! common/verbose? true))
|
||||||
|
|
@ -557,7 +567,6 @@ Use -- to separate script command line args from bb command line args.
|
||||||
:else
|
:else
|
||||||
(edn/read {:readers edn-readers} *in*))))))
|
(edn/read {:readers edn-readers} *in*))))))
|
||||||
uberscript-sources (atom ())
|
uberscript-sources (atom ())
|
||||||
env (atom {})
|
|
||||||
classpath (or classpath
|
classpath (or classpath
|
||||||
(System/getenv "BABASHKA_CLASSPATH"))
|
(System/getenv "BABASHKA_CLASSPATH"))
|
||||||
_ (when classpath
|
_ (when classpath
|
||||||
|
|
@ -699,10 +708,13 @@ Use -- to separate script command line args from bb command line args.
|
||||||
:verbose? verbose?
|
:verbose? verbose?
|
||||||
:preloads preloads
|
:preloads preloads
|
||||||
:loader (:loader @cp/cp-state)}))))
|
:loader (:loader @cp/cp-state)}))))
|
||||||
exec-fn [nil (exec-fn)]
|
exec-fn [(exec-fn) 0]
|
||||||
clojure (if-let [proc (deps/clojure (:opts opts))]
|
exec-src [(sci/binding [sci/file (or @sci/file "<task: >")]
|
||||||
|
(sci/eval-string* sci-ctx exec-src))
|
||||||
|
0]
|
||||||
|
clojure [nil (if-let [proc (deps/clojure (:opts opts))]
|
||||||
(-> @proc :exit)
|
(-> @proc :exit)
|
||||||
0)
|
0)]
|
||||||
uberscript [nil 0]
|
uberscript [nil 0]
|
||||||
:else [(repl/start-repl! sci-ctx) 0]))
|
:else [(repl/start-repl! sci-ctx) 0]))
|
||||||
1)]
|
1)]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
(ns user)
|
(ns user
|
||||||
|
(:require [babashka.process :as p]
|
||||||
|
[clojure.string :as str]))
|
||||||
|
|
||||||
(defn bash [& args]
|
(defn bash [& args]
|
||||||
(prn :args args))
|
(-> (p/process ["bash" "-c" (str/join " " args)]
|
||||||
|
{:inherit true})
|
||||||
|
p/check))
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
{:paths ["test-resources/bb-edn"]
|
{:paths ["test-resources/bb-edn"]
|
||||||
:tasks {:count-files {:task/type :shell
|
:tasks {:count-files {:task/type :shell
|
||||||
:args ["bash" "-c" "ls | wc -l"]}
|
:args ["bash" "-c" "ls | wc -l"]}
|
||||||
:bash {:task/type :babashka
|
:bash {:task/type :fn
|
||||||
:args [:invoke user/bash]}
|
:var user/bash}
|
||||||
:eval-plus {:type :babashka
|
:eval-plus {:task/type :babashka
|
||||||
:args [-e (apply + (map (fn [i]
|
:args [-e (apply + (map (fn [i]
|
||||||
(Integer/parseInt i))
|
(Integer/parseInt i))
|
||||||
*command-line-args*))]}
|
*command-line-args*))]}
|
||||||
:tree {:task/type :babashka
|
:tree {:task/type :babashka
|
||||||
:args [:clojure -Stree]}
|
:args [:clojure -Stree]}
|
||||||
:all {:task/type :babashka
|
:all {:task/type :babashka
|
||||||
:args [:do :eval-plus 1 2 3
|
:args [:do :count-files
|
||||||
:__ :tree
|
:__ :bash "ls | wc -l"
|
||||||
:__ :bash "ls | wc -l"]}}}
|
:__ :eval-plus 1 2 3
|
||||||
|
:__ :tree]}}}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue