This commit is contained in:
Michiel Borkent 2021-03-27 16:47:38 +01:00
parent d8cd25a84d
commit ab3b4fa53a
2 changed files with 34 additions and 53 deletions

View file

@ -171,14 +171,16 @@ Use -- to separate script command line args from bb command line args.
(let [main (if (simple-symbol? main)
(symbol (str main) "-main")
main)]
(if-let [doc (sci/eval-string* ctx (format "(some-> (requiring-resolve '%s) meta :doc)" main))]
[(println doc) 0]
(if (sci/eval-string* ctx (format "(when (requiring-resolve '%1$s)
(clojure.repl/doc %1$s) true)" main))
[nil 0]
[(print-error "No docstring found for task:" k) 1]))
[(print-error "No docstring found for task:" k) 1])))
[(print-error "Task does not exist:" k) 1]))
(let [arg (if (str/includes? arg "/") arg (str "clojure.core/" arg))]
(if-let [doc (sci/eval-string* ctx (format "(some-> (requiring-resolve '%s) meta :doc)" arg))]
[(println doc) 0]
(if (sci/eval-string* ctx (format "(when (requiring-resolve '%1$s)
(clojure.repl/doc %1$s) true)" arg))
[nil 0]
[(print-error "No docstring found for var:" arg) 1]))))
,)

View file

@ -2,61 +2,40 @@
:deps {medley/medley {:mvn/version "1.3.0"}} ;; no-brainer to support this
;; here comes the part that is currently uncertain
:tasks {:count-files {:task/type :shell
:args ["bash" "-c" "ls | wc -l"]}
:bash {:task/type :babashka
:args [:invoke user/bash]}
:eval-plus {:task/type :babashka
:args [-e (apply + (map (fn [i]
(Integer/parseInt i))
*command-line-args*))]}
:describe {:task/type :babashka
:args [:clojure -Sdescribe]}
: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"
:__ :eval-plus 1 2 3
:__ :describe]}
:tasks {:count-files [shell "bash" "-c" "ls | wc -l"]
:bash [babashka user/bash]
:eval-plus [babashka -e (apply + (map (fn [i]
(Integer/parseInt i))
*command-line-args*))]
:describe [babashka clojure -Sdescribe]
:do-bash [do
[:bash "ls | wc -l"]
[:eval-plus 1 2 3]]
:all [do
[:count-files]
[:bash "ls | wc -l"]
[:eval-plus 1 2 3]
[:describe]]
;;;;
:never-failing-shell
{:task/type :babashka
;; we are executing a shell task, yet we are continueing despite the error code
:args [-e (-> (do (deref (babashka.process/process ["ls" "foobar"] {:inherit true}))
(deref (babashka.process/process ["echo" "done"] {:inherit true}))
nil))]}
:print-hello {:task/type :babashka
:args [-e (println :hello)]}
:always-failing-shell
{:task/type :babashka
;; we are executing a shell task, yet we are continueing despite the error code
:args [-e (babashka.process/check (babashka.process/process ["ls" "foobar"] {:inherit true}))]}
:composed-never-failing {:task/type :babashka
:args [:do :never-failing-shell
:__ :print-hello]}
:composed-failing {:task/type :babashka
:args [:do :always-failing-shell
:__ :print-hello]}
[babashka -e (-> (do (deref (babashka.process/process ["ls" "foobar"] {:inherit true}))
(deref (babashka.process/process ["echo" "done"] {:inherit true}))
nil))]
:print-hello [babashka -e (println :hello)]
:always-failing-shell [babashka -e (babashka.process/check (babashka.process/process ["ls" "foobar"] {:inherit true}))]
:composed-never-failing [do
[:never-failing-shell]
[:print-hello]]
:composed-failing [do
[:always-failing-shell]
[:print-hello]]
,
;;;; help
:cool-task {:task/type :babashka
:args ["-e" "(+ 1 2 3)"]
:task/help "Usage: bb :cool-task
:cool-task {:doc "Usage: bb :cool-task
Sum up the numbers 1, 2 and 3."}
Sum up the numbers 1, 2 and 3."
:task [babashka "-e" "(+ 1 2 3)"]}
,
;;;; context (not implemented)
;; the problem with this is the DSL nature which is very opiniated and
;; maybe not so nice to learn for people who only want to write Clojure
:put-answer-in-ctx {:type/task :babashka
:args [:eval-plus 1 2 3]
:out [:answer]}
:print-answer {:type/task :babashka
:in {:sum [:answer]}
:args [-e (println $sum)]}
}
}