This commit is contained in:
Michiel Borkent 2021-03-20 17:16:03 +01:00
parent 7cc4867212
commit 9b9c6f0d36
2 changed files with 34 additions and 4 deletions

View file

@ -148,6 +148,15 @@ Use -- to separate script command line args from bb command line args.
,)) ;; end if ,)) ;; end if
,) ;; end defn ,) ;; end defn
(defn print-tasks [tasks]
(println "The following tasks are available:")
(println)
(doseq [k (keys tasks)]
(println k))
(println)
(println "Run bb :help <task> to view help of a specific task.")
[nil 0])
(defn print-describe [] (defn print-describe []
(println (println
(format (format
@ -397,6 +406,8 @@ Use -- to separate script command line args from bb command line args.
("--version" ":version") {:version true} ("--version" ":version") {:version true}
("--help" "-h" "-?" ":help") {:help true ("--help" "-h" "-?" ":help") {:help true
:command-line-args (rest options)} :command-line-args (rest options)}
(":tasks") {:tasks tasks
:command-line-args (rest options)}
("--verbose")(recur (next options) ("--verbose")(recur (next options)
(assoc opts-map (assoc opts-map
:verbose? true)) :verbose? true))
@ -499,7 +510,7 @@ Use -- to separate script command line args from bb command line args.
(= % ":or-do")))) (= % ":or-do"))))
options)] options)]
{:do options}) {:do options})
(":invoke") #_#_(":invoke")
{:exec-src {:exec-src
(pr-str '(if-let [f (requiring-resolve (symbol (first *command-line-args*)))] (pr-str '(if-let [f (requiring-resolve (symbol (first *command-line-args*)))]
(apply f (rest *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 :verbose? :classpath
:main :uberscript :describe? :main :uberscript :describe?
:jar :uberjar :clojure :jar :uberjar :clojure
:exec-src] :exec-src :tasks]
exec-fn :exec} exec-fn :exec}
opts opts
_ (when verbose? (vreset! common/verbose? true)) _ (when verbose? (vreset! common/verbose? true))
@ -683,8 +694,8 @@ Use -- to separate script command line args from bb command line args.
(second (second
(cond version-opt (cond version-opt
[(print-version) 0] [(print-version) 0]
help help (print-help command-line-args)
(print-help command-line-args) tasks (print-tasks tasks)
describe? describe?
[(print-describe) 0] [(print-describe) 0]
repl [(repl/start-repl! sci-ctx) 0] repl [(repl/start-repl! sci-ctx) 0]

View file

@ -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 (is (str/includes? (apply test-utils/bb nil
(map str [:help :cool-task])) (map str [:help :cool-task]))
"Usage: bb :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")))))