diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 188c4ec3..83e0bff1 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -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 diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 5e7271db..332c6332 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -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)"]}