This commit is contained in:
Michiel Borkent 2021-03-22 12:03:32 +01:00
parent 289c589215
commit be47d673f5
2 changed files with 25 additions and 3 deletions

View file

@ -396,13 +396,22 @@ Use -- to separate script command line args from bb command line args.
(defn parse-opts [options]
(let [fst (when options (first options))
key? (when fst (str/starts-with? fst ":"))
k (when key? (keyword (subs fst 1)))
keys (when key? (rest (str/split fst #":")))
expanded (when (and key? (> (count keys) 1))
(concat (cons ":do" (interpose ":and-do"
(map #(str ":" %)
keys)))
(rest options)))
k (when (and key? (not expanded))
(keyword (first keys)))
bb-edn (when k @bb-edn)
tasks (when (and k bb-edn)
(:tasks bb-edn))
user-task (when tasks (get tasks k))]
(if user-task
(cond user-task
(resolve-task user-task {:command-line-args (next options)})
expanded (parse-opts expanded)
:else
(let [opts (loop [options options
opts-map {}]
(if options

View file

@ -48,7 +48,20 @@
(is (fs/exists? temp-file))
(let [res (bb :all)]
(is (= 6 res)))
(is (not (fs/exists? temp-file))))))
(is (not (fs/exists? temp-file)))))
(testing ":and-do shortcut"
(let [temp-dir (fs/create-temp-dir)
temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))]
(with-config {:tasks {:clean {:task/type :shell
:args ["rm" (str temp-file)]}
:sum {:task/type :babashka
:args ["-e" "(+ 1 2 3)"]}
:all {:task/type :babashka
:args [:do :clean :and-do :sum]}}}
(is (fs/exists? temp-file))
(let [res (bb :clean:sum)]
(is (= 6 res)))
(is (not (fs/exists? temp-file)))))))
(testing ":do always continuing"
(with-config {:tasks {:sum-1 {:task/type :babashka
:args ["-e" "(do (+ 4 5 6) nil)"]}