[#796] Support map literal in task

This commit is contained in:
Michiel Borkent 2021-04-24 13:05:27 +02:00
parent 3e9ddc55bb
commit 5ff9d8328a
2 changed files with 18 additions and 17 deletions

View file

@ -100,7 +100,10 @@
(assemble-task-1 task-name task parallel? nil nil))
([task-name task parallel? last?] (assemble-task-1 task-name task parallel? last? nil))
([task-name task parallel? last? depends]
(cond (qualified-symbol? task)
(let [[task depends] (if (map? task)
[(:task task) (:depends task)]
[task depends])]
(if (qualified-symbol? task)
(let [prog (format "(apply %s *command-line-args*)" task)
prog (wrap-depends prog depends parallel?)
prog (wrap-def task-name prog parallel? last?)
@ -110,12 +113,9 @@
(namespace task)
prog)]
prog)
(map? task)
(let [t (:task task)]
(assemble-task-1 task-name t parallel? last? (:depends task)))
:else (let [task (pr-str task)
(let [task (pr-str task)
prog (wrap-depends task depends parallel?)]
(wrap-def task-name prog parallel? last?)))))
(wrap-def task-name prog parallel? last?))))))
(defn format-task [init requires prog]
(format "

View file

@ -77,8 +77,6 @@
foo {:depends [bar]
:task (fs/exists? ".")}}}
(is (= true (bb "foo")))))
;; Note: this behavior with :when was complex, since the place where :when
;; is inserted isn't very intuitive here
;; This is why we don't support :when for now
#_(testing "depends with :when"
(test-utils/with-config {:tasks {'quux (list 'spit out "quux\n")
@ -89,7 +87,10 @@
'foo {:depends ['quux 'bar]
:task (list 'spit out "foo\n" :append true)}}}
(bb "foo")
(is (= "quux\nbaz\nbar\nfoo\n" (slurp out)))))))
(is (= "quux\nbaz\nbar\nfoo\n" (slurp out)))))
(testing "map returned from task"
(test-utils/with-config '{:tasks {foo {:task {:a 1 :b 2}}}}
(is (= {:a 1 :b 2} (bb "foo")))))))
(deftest list-tasks-test
(test-utils/with-config {}