Kaynağa Gözat

Factor out the FORMAT NIL pattern in SHELL-COMMAND usage.

Brit Butler 12 yıl önce
ebeveyn
işleme
1cff1093a9
3 değiştirilmiş dosya ile 11 ekleme ve 7 silme
  1. 2 6
      src/coleslaw.lisp
  2. 0 1
      src/packages.lisp
  3. 9 0
      src/util.lisp

+ 2 - 6
src/coleslaw.lisp

@@ -32,15 +32,11 @@ If RAW is non-nil, write the content without wrapping it in the base template."
32 32
           (static-dir (merge-pathnames "static" (repo *config*))))
33 33
       (dolist (dir (list css-dir static-dir))
34 34
         (when (probe-file dir)
35
-          (shell-command (format nil "cp -R ~a ." dir)))))
35
+          (run-program "cp -R ~a ." dir))))
36 36
     (render-posts)
37 37
     (render-indices)
38 38
     (render-feed)))
39 39
 
40
-(defun update-symlink (path target)
41
-  "Update the symlink at PATH to point to TARGET."
42
-  (shell-command (format nil "ln -sfn ~a ~a" target path)))
43
-
44 40
 (defgeneric deploy (staging)
45 41
   (:documentation "Deploy the STAGING dir, updating the .prev and .curr symlinks.")
46 42
   (:method (staging)
@@ -51,7 +47,7 @@ If RAW is non-nil, write the content without wrapping it in the base template."
51 47
             (curr (deploy-path ".curr")))
52 48
         (ensure-directories-exist new-build)
53 49
         (with-current-directory coleslaw-conf:*basedir*
54
-          (shell-command (format nil "mv ~a ~a" staging new-build))
50
+          (run-program "mv ~a ~a" staging new-build)
55 51
           (if (and (probe-file prev) (equal prev (truename prev)))
56 52
               (delete-file prev)
57 53
               (cl-fad:delete-directory-and-files (truename prev)))

+ 0 - 1
src/packages.lisp

@@ -1,7 +1,6 @@
1 1
 (defpackage :coleslaw
2 2
   (:documentation "Homepage: <a href=\"http://github.com/redline6561/coleslaw\">Github</a>")
3 3
   (:use :cl :closure-template)
4
-  (:import-from :trivial-shell #:shell-command)
5 4
   (:import-from :iolib.os #:with-current-directory)
6 5
   (:import-from :alexandria #:hash-table-values
7 6
                             #:make-keyword)

+ 9 - 0
src/util.lisp

@@ -5,6 +5,15 @@
5 5
 If ARGS is provided, use (apply 'format nil PATH ARGS) as the value of PATH."
6 6
   (merge-pathnames (apply 'format nil path args) coleslaw-conf:*basedir*))
7 7
 
8
+(defun run-program (program &rest args)
9
+  "Take a PROGRAM and execute the corresponding shell command. If ARGS is provided,
10
+use (apply 'format nil PROGRAM ARGS) as the value of PROGRAM."
11
+  (trivial-shell:shell-command (apply 'format nil program args)))
12
+
13
+(defun update-symlink (path target)
14
+  "Update the symlink at PATH to point to TARGET."
15
+  (run-program "ln -sfn ~a ~a" target path))
16
+
8 17
 (defmacro do-files ((var path &optional extension) &body body)
9 18
   "For each file on PATH, run BODY. If EXTENSION is provided, only run BODY
10 19
 on files that match the given extension."