diff --git a/src/babashka/impl/tasks.clj b/src/babashka/impl/tasks.clj index a9ce0273..3aedd0f8 100644 --- a/src/babashka/impl/tasks.clj +++ b/src/babashka/impl/tasks.clj @@ -235,7 +235,7 @@ (println "No such task:" task-name)) 1]))) (defn list-tasks - [] + [sci-ctx] (let [tasks (:tasks @bb-edn)] (if (seq tasks) (let [names (keys tasks) @@ -251,7 +251,11 @@ (doseq [k names :let [task (get tasks (symbol k))]] (let [task (if (qualified-symbol? task) - {:doc (format "Runs %s. See `bb doc %s` for more info." task task)} + {:doc (sci/eval-string* + sci-ctx + (format " +(try (require '%s) (catch Exception _ nil)) +(:doc (meta (resolve '%s)))" (namespace task) task))} task)] (println (str (format fmt k) (when-let [d (:doc task)] diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 82b4f9f8..e5f64d74 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -735,7 +735,7 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") repl [(repl/start-repl! sci-ctx) 0] nrepl [(start-nrepl! nrepl sci-ctx) 0] uberjar [nil 0] - list-tasks [(tasks/list-tasks) 0] + list-tasks [(tasks/list-tasks sci-ctx) 0] expressions (sci/binding [sci/file abs-path] (try diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 4e44c1d1..81c8b37f 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -96,7 +96,8 @@ (test-utils/with-config {} (let [res (test-utils/bb nil "tasks")] (is (str/includes? res "No tasks found.")))) - (test-utils/with-config {:tasks {'task1 + (test-utils/with-config {:paths ["test-resources/task_scripts"] + :tasks {'task1 {:doc "task1 doc" :task '(+ 1 2 3)} 'task2 @@ -106,9 +107,12 @@ {:task '(+ 1 2 3)} 'task4 {:task '(+ 1 2 3) - :private true}}} + :private true} + 'foo 'tasks/foo + 'bar 'non-existing/bar}} (let [res (test-utils/bb nil "tasks")] - (is (= "The following tasks are available:\n\ntask1 task1 doc\ntask2 task2 doc\n" res))))) + (is (= "The following tasks are available:\n\nbar \nfoo Foo docstring\ntask1 task1 doc\ntask2 task2 doc\n" + res))))) (deftest task-priority-test (when-not test-utils/native?