forked from technomancy/leiningen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdo.clj
More file actions
40 lines (33 loc) · 1.23 KB
/
Copy pathdo.clj
File metadata and controls
40 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(ns leiningen.do
"Higher-order task to perform other tasks in succession."
(:refer-clojure :exclude [do])
(:require [leiningen.core.main :as main]))
(defn- conj-to-last [coll x]
(update-in coll [(dec (count coll))] conj x))
(defn- butlast-char
"Removes the last character in the string."
[s]
(subs s 0 (dec (count s))))
(defn- pop-if-last
"Pops the collection if (pred (peek coll)) is truthy."
[coll pred]
(if (pred (peek coll))
(pop coll)
coll))
(defn ^:internal group-args
([args] (-> (reduce group-args [[]] args)
(pop-if-last empty?)))
([groups arg]
(cond (coll? arg) (-> (pop-if-last groups empty?)
(conj arg []))
(.endsWith arg ",") (-> groups
(conj-to-last (butlast-char arg))
(conj []))
:else (conj-to-last groups arg))))
(defn ^:no-project-needed ^:higher-order do
"Higher-order task to perform other tasks in succession.
Each comma-separated group should be a task name followed by optional arguments.
USAGE: lein do test, compile :all, deploy private-repo"
[project & args]
(doseq [arg-group (group-args args)]
(main/resolve-and-apply project arg-group)))