From 6abe9a6851094e6be8aed3001f9c0be96181a37a Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Tue, 23 Mar 2021 11:15:01 +0100 Subject: [PATCH] Add sorting and task/description --- src/babashka/main.clj | 15 ++++++++------- test/babashka/bb_edn_test.clj | 8 +++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index ea894b8a..cd81c5c5 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -157,13 +157,14 @@ Use -- to separate script command line args from bb command line args. ,) ;; 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]) + (let [tasks (into (sorted-map) tasks)] + (println "The following tasks are available:") + (println) + (doseq [[k v] tasks] + (println k (:task/description v))) + (println) + (println "Run bb :help to view help of a specific task.") + [nil 0])) (defn print-describe [] (println diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 332c6332..e2c870ff 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -123,12 +123,14 @@ Addition is a pretty advanced topic. Let us start with the identity element (deftest list-tasks-test (with-config {:tasks {:cool-task-1 {:task/type :babashka :args ["-e" "(+ 1 2 3)"] + :task/description "Return the sum of 1, 2 and 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/description "Return the sum of 4, 5 and 6." + :args ["-e" "(+ 4 5 6)"] :task/help "Usage: bb :cool-task Addition is a pretty advanced topic. Let us start with the identity element @@ -136,8 +138,8 @@ Addition is a pretty advanced topic. Let us start with the identity element (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"))))) + (is (str/includes? res ":cool-task-1 Return the")) + (is (str/includes? res ":cool-task-2 Return the"))))) (deftest main-task-test (with-config {:paths ["test-resources/task_scripts"]