From 1cff1093a9d3b1f04a2cd20e9c8ce484372fce43 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Wed, 29 Aug 2012 11:34:05 -0400 Subject: [PATCH] Factor out the FORMAT NIL pattern in SHELL-COMMAND usage. --- src/coleslaw.lisp | 8 ++------ src/packages.lisp | 1 - src/util.lisp | 9 +++++++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/coleslaw.lisp b/src/coleslaw.lisp index 06c6fb8..01968f6 100644 --- a/src/coleslaw.lisp +++ b/src/coleslaw.lisp @@ -32,15 +32,11 @@ If RAW is non-nil, write the content without wrapping it in the base template." (static-dir (merge-pathnames "static" (repo *config*)))) (dolist (dir (list css-dir static-dir)) (when (probe-file dir) - (shell-command (format nil "cp -R ~a ." dir))))) + (run-program "cp -R ~a ." dir)))) (render-posts) (render-indices) (render-feed))) -(defun update-symlink (path target) - "Update the symlink at PATH to point to TARGET." - (shell-command (format nil "ln -sfn ~a ~a" target path))) - (defgeneric deploy (staging) (:documentation "Deploy the STAGING dir, updating the .prev and .curr symlinks.") (:method (staging) @@ -51,7 +47,7 @@ If RAW is non-nil, write the content without wrapping it in the base template." (curr (deploy-path ".curr"))) (ensure-directories-exist new-build) (with-current-directory coleslaw-conf:*basedir* - (shell-command (format nil "mv ~a ~a" staging new-build)) + (run-program "mv ~a ~a" staging new-build) (if (and (probe-file prev) (equal prev (truename prev))) (delete-file prev) (cl-fad:delete-directory-and-files (truename prev))) diff --git a/src/packages.lisp b/src/packages.lisp index ddd2a1e..f094199 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -1,7 +1,6 @@ (defpackage :coleslaw (:documentation "Homepage: Github") (:use :cl :closure-template) - (:import-from :trivial-shell #:shell-command) (:import-from :iolib.os #:with-current-directory) (:import-from :alexandria #:hash-table-values #:make-keyword) diff --git a/src/util.lisp b/src/util.lisp index 6c9eb23..7c8bcdc 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -5,6 +5,15 @@ If ARGS is provided, use (apply 'format nil PATH ARGS) as the value of PATH." (merge-pathnames (apply 'format nil path args) coleslaw-conf:*basedir*)) +(defun run-program (program &rest args) + "Take a PROGRAM and execute the corresponding shell command. If ARGS is provided, +use (apply 'format nil PROGRAM ARGS) as the value of PROGRAM." + (trivial-shell:shell-command (apply 'format nil program args))) + +(defun update-symlink (path target) + "Update the symlink at PATH to point to TARGET." + (run-program "ln -sfn ~a ~a" target path)) + (defmacro do-files ((var path &optional extension) &body body) "For each file on PATH, run BODY. If EXTENSION is provided, only run BODY on files that match the given extension."