This commit is contained in:
Michiel Borkent 2021-03-16 11:44:31 +01:00
parent 23834a5302
commit ae397e20e7
3 changed files with 11 additions and 5 deletions

View file

@ -1,5 +1,6 @@
(ns babashka.cli (ns babashka.cli
(:require [babashka.fs :as fs] (:require [babashka.fs :as fs]
[babashka.process :as p]
[clojure.edn :as edn] [clojure.edn :as edn]
[clojure.string :as str])) [clojure.string :as str]))
@ -143,8 +144,12 @@
(if (fs/exists? bb-edn-file) (if (fs/exists? bb-edn-file)
(let [bb-edn (edn/read-string (slurp bb-edn-file))] (let [bb-edn (edn/read-string (slurp bb-edn-file))]
(if-let [task (get-in bb-edn [:tasks (keyword (subs task 1))])] (if-let [task (get-in bb-edn [:tasks (keyword (subs task 1))])]
(let [cmd-line-args (get task :babashka/args)] (let [cmd-line-args (get task :babashka/args)
proc (get task :babashka/process)]
;; 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)))) (cond cmd-line-args
(parse-opts (seq (concat cmd-line-args command-line-args)))
proc (do (-> proc (p/process {:inherit true}) p/check)
{:exit-code 0})))
(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))))

View file

@ -527,7 +527,7 @@ Use -- to separate script command line args from bb command line args.
:preloads preloads :preloads preloads
:loader (:loader @cp/cp-state)})))) :loader (:loader @cp/cp-state)}))))
uberscript [nil 0] uberscript [nil 0]
(not task) [(repl/start-repl! sci-ctx) 0])) :else [(repl/start-repl! sci-ctx) 0]))
1)] 1)]
(flush) (flush)
(when uberscript (when uberscript

View file

@ -1,2 +1,3 @@
{:tasks {:eval-plus {:babashka/args ["-e" "(+ 1 2 3)"]} {:tasks {:eval-plus {:babashka/args ["-e" "(+ 1 2 3)"]}
:tree {:babashka/args [":clojure" "-Stree"]}}} :tree {:babashka/args [":clojure" "-Stree"]}
:count-files {:babashka/process ["bash" "-c" "ls | wc -l"] }}}