From 9b9c6f0d36fba6cb8d028709cd70aced8f86fa40 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 20 Mar 2021 17:16:03 +0100 Subject: [PATCH] wip --- src/babashka/main.clj | 19 +++++++++++++++---- test/babashka/bb_edn_test.clj | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index fda84fbb..a8a2a26d 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -148,6 +148,15 @@ Use -- to separate script command line args from bb command line args. ,)) ;; end if ,) ;; end defn +(defn print-tasks [tasks] + (println "The following tasks are available:") + (println) + (doseq [k (keys tasks)] + (println k)) + (println) + (println "Run bb :help to view help of a specific task.") + [nil 0]) + (defn print-describe [] (println (format @@ -397,6 +406,8 @@ Use -- to separate script command line args from bb command line args. ("--version" ":version") {:version true} ("--help" "-h" "-?" ":help") {:help true :command-line-args (rest options)} + (":tasks") {:tasks tasks + :command-line-args (rest options)} ("--verbose")(recur (next options) (assoc opts-map :verbose? true)) @@ -499,7 +510,7 @@ Use -- to separate script command line args from bb command line args. (= % ":or-do")))) options)] {:do options}) - (":invoke") + #_#_(":invoke") {:exec-src (pr-str '(if-let [f (requiring-resolve (symbol (first *command-line-args*)))] (apply f (rest *command-line-args*)) @@ -560,7 +571,7 @@ Use -- to separate script command line args from bb command line args. :verbose? :classpath :main :uberscript :describe? :jar :uberjar :clojure - :exec-src] + :exec-src :tasks] exec-fn :exec} opts _ (when verbose? (vreset! common/verbose? true)) @@ -683,8 +694,8 @@ Use -- to separate script command line args from bb command line args. (second (cond version-opt [(print-version) 0] - help - (print-help command-line-args) + help (print-help command-line-args) + tasks (print-tasks tasks) describe? [(print-describe) 0] repl [(repl/start-repl! sci-ctx) 0] diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index f7d9ec38..5653a506 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -106,3 +106,22 @@ Addition is a pretty advanced topic. Let us start with the identity element (is (str/includes? (apply test-utils/bb nil (map str [:help :cool-task])) "Usage: bb :cool-task")))) + +(deftest list-tasks-test + (with-config {:tasks {:cool-task-1 {:task/type :babashka + :args ["-e" "(+ 1 2 3)"] + :task/help "Usage: bb :cool-task + +Addition is a pretty advanced topic. Let us start with the identity element +0. ..."} + :cool-task-2 {:task/type :babashka + :args ["-e" "(+ 1 2 3)"] + :task/help "Usage: bb :cool-task + +Addition is a pretty advanced topic. Let us start with the identity element +0. ..."}}} + (let [res (apply test-utils/bb nil + (map str [:tasks]))] + (is (str/includes? res "The following tasks are available:")) + (is (str/includes? res ":cool-task-1")) + (is (str/includes? res ":cool-task-2")))))