Tasks: integrate in doc subcommand

This commit is contained in:
Michiel Borkent 2021-05-02 20:48:40 +02:00
parent 76a6760516
commit d0d18f9837
2 changed files with 96 additions and 82 deletions

View file

@ -162,8 +162,18 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
[nil 0])
(defn print-doc [ctx command-line-args]
(let [arg (first command-line-args)]
(if (sci/eval-string* ctx (format "
(let [arg (first command-line-args)
tasks (:tasks @common/bb-edn)]
(if (or (when-let [s (tasks/doc-from-task
ctx
tasks
(get tasks (symbol arg)))]
[(do (println "-------------------------")
(println arg)
(println "Task")
(println s)
true) 0])
(sci/eval-string* ctx (format "
(when (or (resolve '%1$s)
(if (simple-symbol? '%1$s)
(try (require '%1$s) true
@ -171,7 +181,7 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
(try (requiring-resolve '%1$s) true
(catch Exception e nil))))
(clojure.repl/doc %1$s)
true)" arg))
true)" arg)))
[nil 0]
[nil 1]))
,)

View file

@ -182,7 +182,11 @@
:task (+ a 4 5 6)}}}
(is (thrown-with-msg?
Exception #"Cyclic task: b"
(bb "run" "b"))))))
(bb "run" "b")))))
(testing "doc"
(test-utils/with-config '{:tasks {b {:doc "Beautiful docstring"}}}
(let [s (test-utils/bb nil "doc" "b")]
(is (= "-------------------------\nb\nTask\nBeautiful docstring\n" s)))))
(deftest list-tasks-test
(test-utils/with-config {}
@ -215,7 +219,7 @@
:task (+ 1 2 3)}}}"
(let [res (test-utils/bb nil "tasks")]
(is (= "The following tasks are available:\n\ntask1 task1 doc\n"
res))))))
res)))))))
(deftest task-priority-test
(when-not test-utils/native?