forked from emacs-taskrunner/emacs-taskrunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskrunner-general.el
315 lines (283 loc) · 11.3 KB
/
taskrunner-general.el
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
;;; taskrunner-general.el --- Provide functions to access general taskrunners not tied to any language -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Yavor Konstantinov
;;; Commentary:
;; This file provides support for general taskrunners which are not tied to
;; a specific language.
;; Support included for:
;; Golang's Task
;; Mage
;; cargo-make
;; mask
;; just
;; doit
;;; Code:
;;;; Required
(require 'projectile)
(require 'cl-lib)
;;;; Variables
(defcustom taskrunner-go-task-bin-path "~/go/bin/"
"Path used to locate the `task' taskrunner binary."
:group 'taskrunner
:type 'string)
(defcustom taskrunner-mage-bin-path "~/go/bin/"
"Path used to locate the `mage' taskrunner binary."
:group 'taskrunner
:type 'string)
(defcustom taskrunner-doit-bin-path "~/.local/bin/"
"Path used to locate the `doit' taskrunner binary."
:group 'taskrunner
:type 'string)
(defcustom taskrunner-tusk-bin-path "~/clones/tusk-test/"
"Path to the Tusk taskrunner binary."
:group 'taskrunner
:type 'string)
(defcustom taskrunner-dobi-bin-path "~/"
"Path to the folder containing the Dobi taskrunner binary."
:group 'taskrunner
:type 'string)
(defcustom taskrunner-dobi-bin-name "dobi-linux"
"Name of the Dobi taskrunner binary."
:group 'taskrunner
:type 'string)
;;;; Functions
;; These are here just to silence the bytecompiler. They are defined in
;; `taskrunner.el' and will be loaded later on but due to these files being
;; required before the function being loaded, a warning is emitted.
(declare-function taskrunner--narrow-to-line "ext:taskrunner")
(declare-function taskrunner--make-task-buff-name "ext:taskrunner")
(defun taskrunner--get-go-tasks-from-buffer ()
"Retrieve all go tasks from the currently visited buffer.
The tasks are returned in the form:
\(\"TASK TASK-NAME\" ...)"
(interactive)
(let ((targets '()))
(goto-char (point-min))
(while (search-forward-regexp "^\*" nil t)
(taskrunner--narrow-to-line)
(push (car (split-string (cadr (split-string (buffer-string) " ")) ":")) targets)
(widen))
(kill-current-buffer)
(if targets
(cl-map 'list (lambda (elem)
(concat "TASK" " " elem))
targets)
targets)))
(defun taskrunner-get-go-task-tasks (DIR)
"Retrieve the golang Task tasks for the project in directory DIR.
This function returns a list of the form:
\(\"TASK TASK1\" \"TASK TASK2\"...)"
(let ((default-directory DIR)
(exec-path (cons taskrunner-go-task-bin-path exec-path)))
(call-process "task" nil (taskrunner--make-task-buff-name "go-task") nil "-l")
(with-temp-buffer
(set-buffer (taskrunner--make-task-buff-name "go-task"))
(taskrunner--get-go-tasks-from-buffer))))
(defun taskrunner--get-mage-tasks-from-buffer ()
"Retrieve all mage tasks from the currently visited buffer."
(let ((targets '())
(beg nil))
(goto-char (point-min))
(setq beg (search-forward-regexp "Targets:\n" nil t))
(when beg
(narrow-to-region (point-at-bol) (point-max))
(dolist (elem (split-string (buffer-string) "\n"))
(push (car (split-string elem " " t)) targets)
(if (null (car targets))
(pop targets))))
(kill-current-buffer)
(cl-map 'list (lambda (elem)
(concat "MAGE" " " elem))
targets)))
(defun taskrunner-get-mage-tasks (DIR)
"Retrieve the mage tasks for the project in directory DIR.
This function returns a list of the form:
\(\"MAGE TASK1\" \"MAGE TASK2\"...)"
(let ((default-directory DIR)
(exec-path (cons taskrunner-mage-bin-path exec-path)))
(call-process "mage" nil (taskrunner--make-task-buff-name "mage") nil "-l")
(with-temp-buffer
(set-buffer (taskrunner--make-task-buff-name "mage"))
(taskrunner--get-mage-tasks-from-buffer))))
(defun taskrunner--get-doit-tasks-from-buffer ()
"Retrieve all doit tasks from the current buffer."
(goto-char (point-min))
(let ((targets '()))
(dolist (elem (split-string (buffer-string) "\n"))
(push (concat "DOIT" " "(car (split-string elem " "))) targets)
)
(kill-current-buffer)
;; Remove the first target since it is null due to double newlines at the
;; end of buffer
(if (not (null targets))
(pop targets))
targets))
(defun taskrunner-get-doit-tasks (DIR)
"Retrieve the mage tasks for the project in directory DIR.
This function returns a list of the form:
\(\"DOIT TASK1\" \"DOIT TASK2\"...)"
(let ((default-directory DIR)
(exec-path (cons taskrunner-doit-bin-path exec-path)))
(call-process "doit" nil (taskrunner--make-task-buff-name "doit") nil "list")
(with-temp-buffer
(set-buffer (taskrunner--make-task-buff-name "doit"))
(taskrunner--get-doit-tasks-from-buffer))))
(defun taskrunner--get-just-tasks-from-buffer ()
"Retrieve all just tasks from the current buffer."
(goto-char (point-min))
(let ((targets '()))
(when (search-forward-regexp "Available recipes:\n" nil t)
(narrow-to-region (point-at-bol) (point-max))
(setq targets (cl-map 'list (lambda (elem)
(concat "JUST" " " (car (split-string elem " " t))))
(split-string (buffer-string) "\n")))
(kill-current-buffer)
(if targets
(butlast targets)
nil))))
(defun taskrunner-get-just-tasks (DIR)
"Retrieve the mage tasks for the project in directory DIR.
This function returns a list of the form:
\(\"JUST TASK1\" \"JUST TASK2\"...)"
(let ((default-directory DIR))
(call-process "just" nil (taskrunner--make-task-buff-name "just") nil "--list")
(with-temp-buffer
(set-buffer (taskrunner--make-task-buff-name "just"))
(taskrunner--get-just-tasks-from-buffer))))
(defun taskrunner--get-mask-tasks-from-buffer ()
"Retrieve all mask tasks from the current buffer."
(goto-char (point-min))
(let ((targets '()))
(when (search-forward-regexp "SUBCOMMANDS:\n" nil t)
(narrow-to-region (point-at-bol) (point-max))
(setq targets (cl-map 'list
(lambda (elem)
(concat "MASK" " " (car (split-string elem " " t))))
(split-string (buffer-string) "\n")))
(kill-current-buffer)
(butlast targets))))
(defun taskrunner-get-mask-tasks (DIR)
"Retrieve the mage tasks for the project in directory DIR.
This function returns a list of the form:
\(\"MASK TASK1\" \"MASK TASK2\"...)"
(let ((default-directory DIR))
(call-process "mask" nil (taskrunner--make-task-buff-name "mask") nil "--help")
(with-temp-buffer
(set-buffer (taskrunner--make-task-buff-name "mask"))
(taskrunner--get-mask-tasks-from-buffer))))
(defun taskrunner--get-cargo-make-tasks-from-buffer ()
"Retrieve all cargo-make tasks from the current buffer."
(goto-char (point-min))
(let ((targets '())
(beg)
(end))
(while (search-forward-regexp "^-+\n" nil t)
(setq beg (point-at-bol))
(search-forward-regexp "^$" nil t)
(forward-line -1)
(setq end (point-at-eol))
(narrow-to-region beg end)
(dolist (el (split-string (buffer-string) "\n"))
(push (concat "CARGO-MAKE" " " (car (split-string el " "))) targets))
(widen))
(kill-current-buffer)
targets))
(defun taskrunner-get-cargo-make-tasks (DIR)
"Retrieve the mage tasks for the project in directory DIR.
This function returns a list of the form:
\(\"CARGO-MAKE TASK1\" \"CARGO-MAKE TASK2\"...)"
(let ((default-directory DIR))
(call-process "cargo" nil (taskrunner--make-task-buff-name "cargo-make") nil "make" "--list-all-steps")
(with-temp-buffer
(set-buffer (taskrunner--make-task-buff-name "cargo-make"))
(taskrunner--get-cargo-make-tasks-from-buffer))))
(defun taskrunner--get-tusk-tasks-from-buffer ()
"Retrieve all tusk tasks from buffer if any exist."
(goto-char (point-min))
(let ((beg (search-forward-regexp "^Tasks:" nil t))
(end)
(tasks '()))
(when beg
(setq beg
(progn
(forward-line 1)
(point-at-bol)))
(setq end (progn
(search-forward-regexp "^$" nil t)
(point-at-bol)))
(narrow-to-region beg end)
(dolist (elem (split-string (buffer-string) "\n"))
(push (concat "TUSK" " " (car (split-string elem " " t))) tasks)))
(kill-current-buffer)
;; The last line read is a blank one. This removes the blank task if any
;; have been collected
(when tasks
(pop tasks))
tasks))
(defun taskrunner-get-tusk-tasks (DIR)
"Retrieve the Tusk tasks for the project in directory DIR.
This function returns a list of the form:
\(\"TUSK TASK1\" \"TUSK TASK2\"...)"
(let ((default-directory DIR)
(exec-path (cons taskrunner-tusk-bin-path exec-path)))
(call-process "tusk" nil (taskrunner--make-task-buff-name "tusk") nil "--help")
(with-temp-buffer
(set-buffer (taskrunner--make-task-buff-name "tusk"))
(taskrunner--get-tusk-tasks-from-buffer))))
(defun taskrunner--get-buidler-tasks-from-buffer ()
"Retrieve all tasks from the buidler if any are available."
(goto-char (point-min))
(let ((beg (search-forward-regexp "^AVAILABLE TASKS:\n\n" nil t))
(end)
(tasks '()))
(when beg
(setq beg (point-at-bol))
(setq end
(progn
(search-forward-regexp "^$" nil t)
(point-at-bol)))
(narrow-to-region beg end)
(dolist (line (split-string (buffer-string) "\n"))
(push (concat "BUIDLER" " " (car (split-string line split-string-default-separators t))) tasks)))
(kill-current-buffer)
;; The last line read is a blank one. This removes the blank task if any
;; have been collected
(when tasks
(pop tasks))
tasks))
(defun taskrunner-get-buidler-tasks (DIR)
"Retrieve the Buidler tasks for the project in directory DIR.
This function returns a list of the form:
\(\"BUIDLER TASK1\" \"BUIDLER TASK2\"...)
This function assumes that you have `npx' installed."
(let ((default-directory DIR))
(call-process "npx" nil (taskrunner--make-task-buff-name "buidler") nil "buidler" "--help")
(with-temp-buffer
(set-buffer (taskrunner--make-task-buff-name "buidler"))
(taskrunner--get-buidler-tasks-from-buffer))))
(defun taskrunner--get-dobi-tasks-from-buffer ()
"Retrieve all dobi tasks from buffer if any are available."
(goto-char (point-min))
(let ((beg (search-forward-regexp "Resources:\n" nil t))
(tasks '()))
(when beg
(narrow-to-region (point-at-bol) (point-max))
(dolist (line (split-string (buffer-string) "\n"))
(push (concat "DOBI" " " (car (split-string line split-string-default-separators t))) tasks)))
;; The last line read is a blank one. This removes the blank task if any
;; have been collected
(when tasks
(pop tasks))
(kill-current-buffer)
tasks))
(defun taskrunner-get-dobi-tasks (DIR)
"Retrieve the dobi tasks for the project in directory DIR.
This function returns a list of the form:
\(\"DOBI TASK1\" \"DOBI TASK2\"...)"
(let ((default-directory DIR)
(exec-path (cons taskrunner-dobi-bin-path exec-path)))
(call-process taskrunner-dobi-bin-name nil (taskrunner--make-task-buff-name "dobi") nil "list")
(with-temp-buffer
(set-buffer (taskrunner--make-task-buff-name "dobi"))
(taskrunner--get-dobi-tasks-from-buffer))))
(provide 'taskrunner-general)
;;; taskrunner-general.el ends here