From ab3b4fa53adb8cd9d36ad5ad4102538735552f5c Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 27 Mar 2021 16:47:38 +0100 Subject: [PATCH] dude --- src/babashka/main.clj | 10 +++--- test-resources/bb.edn | 77 ++++++++++++++++--------------------------- 2 files changed, 34 insertions(+), 53 deletions(-) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 778e3600..ce812d13 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -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])))) ,) diff --git a/test-resources/bb.edn b/test-resources/bb.edn index 727f4c9b..7eecbd38 100644 --- a/test-resources/bb.edn +++ b/test-resources/bb.edn @@ -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)]} } }