wip [skip ci]

This commit is contained in:
Michiel Borkent 2021-03-17 13:05:04 +01:00
parent 44f80f2a28
commit afed99ad1b
3 changed files with 33 additions and 16 deletions

View file

@ -515,8 +515,15 @@ Use -- to separate script command line args from bb command line args.
:shell
(let [args (get task :args)]
{:exec (fn []
(p/process args {:inherit true}) p/check
0)}))
(p/process args {:inherit true}) p/check)})
: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 "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"
(volatile! true))
(def env (atom {}))
(defn exec [opts]
(binding [*unrestricted* true]
(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
:verbose? :classpath
:main :uberscript :describe?
:jar :uberjar :clojure]
:jar :uberjar :clojure
:exec-src]
exec-fn :exec}
opts
_ (when verbose? (vreset! common/verbose? true))
@ -557,7 +567,6 @@ Use -- to separate script command line args from bb command line args.
:else
(edn/read {:readers edn-readers} *in*))))))
uberscript-sources (atom ())
env (atom {})
classpath (or classpath
(System/getenv "BABASHKA_CLASSPATH"))
_ (when classpath
@ -699,10 +708,13 @@ Use -- to separate script command line args from bb command line args.
:verbose? verbose?
:preloads preloads
:loader (:loader @cp/cp-state)}))))
exec-fn [nil (exec-fn)]
clojure (if-let [proc (deps/clojure (:opts opts))]
(-> @proc :exit)
0)
exec-fn [(exec-fn) 0]
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)
0)]
uberscript [nil 0]
:else [(repl/start-repl! sci-ctx) 0]))
1)]

View file

@ -1,4 +1,8 @@
(ns user)
(ns user
(:require [babashka.process :as p]
[clojure.string :as str]))
(defn bash [& args]
(prn :args args))
(-> (p/process ["bash" "-c" (str/join " " args)]
{:inherit true})
p/check))

View file

@ -1,15 +1,16 @@
{:paths ["test-resources/bb-edn"]
:tasks {:count-files {:task/type :shell
:args ["bash" "-c" "ls | wc -l"]}
:bash {:task/type :babashka
:args [:invoke user/bash]}
:eval-plus {:type :babashka
:bash {:task/type :fn
:var user/bash}
:eval-plus {:task/type :babashka
:args [-e (apply + (map (fn [i]
(Integer/parseInt i))
*command-line-args*))]}
:tree {:task/type :babashka
:args [:clojure -Stree]}
:all {:task/type :babashka
:args [:do :eval-plus 1 2 3
:__ :tree
:__ :bash "ls | wc -l"]}}}
:args [:do :count-files
:__ :bash "ls | wc -l"
:__ :eval-plus 1 2 3
:__ :tree]}}}