Fix 1430: empty tasks names display list (#1431)

Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>
This commit is contained in:
ikappaki 2022-11-28 09:51:39 +00:00 committed by GitHub
parent cb72f8ba17
commit 6e00354053
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 8 deletions

View file

@ -7,6 +7,10 @@ A preview of the next release can be installed from
[Babashka](https://github.com/babashka/babashka): Native, fast starting Clojure interpreter for scripting
## Unreleased
- [#1430](https://github.com/babashka/babashka/issues/1430): Fix issue with `bb tasks` throwing on empty display tasks list.
## 1.0.166 (2022-11-24)
See the [Testing babashka scripts](https://blog.michielborkent.nl/babashka-test-runner.html) blog post for how to run tests with this release.

View file

@ -429,15 +429,22 @@
(iterate zip/right loc))))
(defn list-tasks
"Prints out the task names found in BB-EDN in the original order
alongside their documentation as retrieved with SCI-CTX.
For a task to be listed
- its name has to be a symbol but should not start with `-`, and
- should not be `:private`."
[sci-ctx]
(let [tasks (:tasks @bb-edn)]
(if (seq tasks)
(let [raw-edn (:raw @bb-edn)
names (key-order raw-edn)
names (map str names)
names (remove #(str/starts-with? % "-") names)
names (remove #(:private (get tasks (symbol %))) names)
longest (apply max (map count names))
(let [tasks (:tasks @bb-edn)
raw-edn (:raw @bb-edn)
names (when (seq tasks)
(->> (key-order raw-edn)
(map str)
(remove #(str/starts-with? % "-"))
(remove #(:private (get tasks (symbol %))))))]
(if (seq names)
(let [longest (apply max (map count names))
fmt (str "%1$-" longest "s")]
(println "The following tasks are available:")
(println)

View file

@ -307,6 +307,25 @@
(test-utils/with-config {}
(let [res (test-utils/bb nil "tasks")]
(is (str/includes? res "No tasks found."))))
(test-utils/with-config '{:tasks {:x 1}}
(let [res (test-utils/bb nil "tasks")]
(is (str/includes? res "No tasks found."))))
(test-utils/with-config '{:tasks {-xyz 5}}
(let [res (test-utils/bb nil "tasks")]
(is (str/includes? res "No tasks found."))))
(test-utils/with-config '{:tasks {xyz {:private true}}}
(let [res (test-utils/bb nil "tasks")]
(is (str/includes? res "No tasks found."))))
(test-utils/with-config '{:tasks {abc 1 xyz 2}}
(let [res (test-utils/bb nil "tasks")]
(is (= "The following tasks are available:\n\nabc\nxyz\n" res))))
(test-utils/with-config '{:tasks {abc 1 xyz {:doc "some text" :tasks 5}
-xyz 3 qrs {:private true}}}
(let [res (test-utils/bb nil "tasks")]
(is (= "The following tasks are available:\n\nabc\nxyz some text\n" res))))
(test-utils/with-config '{:tasks {xyz 1 abc 2}}
(let [res (test-utils/bb nil "tasks")]
(is (= "The following tasks are available:\n\nxyz\nabc\n" res))))
(test-utils/with-config "{:paths [\"test-resources/task_scripts\"]
:tasks {:requires ([tasks :as t])
task1