msgs
This commit is contained in:
parent
283d6db591
commit
d4287f353e
2 changed files with 25 additions and 17 deletions
|
|
@ -95,6 +95,10 @@
|
||||||
{:task task-key
|
{:task task-key
|
||||||
:args args})))
|
:args args})))
|
||||||
|
|
||||||
|
(defn print-error [& msgs]
|
||||||
|
(binding [*out* *err*]
|
||||||
|
(apply println msgs)))
|
||||||
|
|
||||||
(defn print-help [ctx command-line-args]
|
(defn print-help [ctx command-line-args]
|
||||||
(if (empty? command-line-args)
|
(if (empty? command-line-args)
|
||||||
(do
|
(do
|
||||||
|
|
@ -150,12 +154,11 @@ Use -- to separate script command line args from bb command line args.
|
||||||
")
|
")
|
||||||
[nil 0]) ;; end do
|
[nil 0]) ;; end do
|
||||||
(let [k (first command-line-args)
|
(let [k (first command-line-args)
|
||||||
k (keyword (subs k 1))
|
k (keyword (subs k 1))]
|
||||||
task (get-in @bb-edn [:tasks k])
|
(if-let [task (get-in @bb-edn [:tasks k])]
|
||||||
{:keys [:args]
|
(let [{:keys [:args]
|
||||||
task-key :task} (decode-task task)
|
task-key :task} (decode-task task)]
|
||||||
help-text (:help (meta task))]
|
(if-let [help-text (:help (meta task))]
|
||||||
(if help-text
|
|
||||||
[(println help-text) 0]
|
[(println help-text) 0]
|
||||||
(if-let [main (when (= :main task-key)
|
(if-let [main (when (= :main task-key)
|
||||||
(first args))]
|
(first args))]
|
||||||
|
|
@ -164,8 +167,9 @@ Use -- to separate script command line args from bb command line args.
|
||||||
main)]
|
main)]
|
||||||
(if-let [doc (sci/eval-string* ctx (format "(some-> (requiring-resolve '%s) meta :doc)" main))]
|
(if-let [doc (sci/eval-string* ctx (format "(some-> (requiring-resolve '%s) meta :doc)" main))]
|
||||||
[(println doc) 0]
|
[(println doc) 0]
|
||||||
[(println "No help found for task:" k) 1]))
|
[(print-error "No help found for task:" k) 1]))
|
||||||
[(println "No help found for task:" k) 1]))
|
[(print-error "No help found for task:" k) 1])))
|
||||||
|
[(print-error "Task does not exist:" k) 1])
|
||||||
,)) ;; end if
|
,)) ;; end if
|
||||||
,) ;; end defn
|
,) ;; end defn
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,11 @@
|
||||||
(with-config {}
|
(with-config {}
|
||||||
(is (thrown-with-msg?
|
(is (thrown-with-msg?
|
||||||
Exception #"Task does not exist: :sum"
|
Exception #"Task does not exist: :sum"
|
||||||
(bb :sum)))))
|
(bb :sum))))
|
||||||
|
(with-config {}
|
||||||
|
(is (thrown-with-msg?
|
||||||
|
Exception #"Task does not exist: :sum"
|
||||||
|
(bb :help :sum)))))
|
||||||
|
|
||||||
(deftest babashka-task-test
|
(deftest babashka-task-test
|
||||||
(with-config {:tasks {:sum [:babashka "-e" "(+ 1 2 3)"]}}
|
(with-config {:tasks {:sum [:babashka "-e" "(+ 1 2 3)"]}}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue