d9797350547fe8403e6f0679435fe6383f644487
[candle] / src / main / run.lisp
1 (in-package #:candle)
2
3 (defun import-package (pkg)
4  (asdf:load-system pkg))
5
6 (defun run-task (task)
7  (format t "~%~c[1;33mRunning ~:(~A~)~c[0m~%" #\Esc (getf task :name) #\Esc)
8  (if
9   (eval (getf task :directions))
10   (progn (format t "~c[1;32m- ~:(~A~) Passed!~c[0m~%" #\Esc (getf task :name) #\Esc) t)
11   (format t "~c[1;31m- ~:(~A~) Failed!~c[0m~%" #\Esc (getf task :name) #\Esc)))
12
13 (defun run ()
14  "RUN => RESULT
15
16 ARGUMENTS AND VALUES:
17
18   RESULT: a boolean, whether the process was successful
19
20 DESCRIPTION:
21
22   Runs the script specified by the .candle file in the current directory.
23   When completed, the boolean will be returned if it was successful or not."
24  (if
25   (not (probe-file ".candle"))
26   :dot-candle-absent
27   (with-open-file (str ".candle")
28    (asdf:initialize-source-registry `(:source-registry (:tree ,(car (directory "."))) :INHERIT-CONFIGURATION))
29    (mapcar #'import-package (cdr (read str)))
30    (let
31     ((candle-definition (read str)))
32     (format t "Running tasks for ~(~A~)~%" (getf candle-definition :name))
33     (every #'identity (mapcar #'run-task (getf candle-definition :tasks)))))))