Add "export" sub-command to "ros template"

This commit is contained in:
eshamster 2018-02-17 04:34:01 +00:00
parent 1e81f3f290
commit 9202108638
3 changed files with 35 additions and 0 deletions

View file

@ -46,6 +46,10 @@ rewrite [template-name] file rewrite-rule
: Change file name using djula template.Variables {{name}} {{author}} {{email}} {{universal_time}} are available for rewrite-rule.
export [template-name] [directory]
: Export files in current template to current directory.
help
: Show the subcommand help.

View file

@ -21,6 +21,7 @@ exec ros -Q -m roswell -N roswell -- $0 "$@"
("type" . template-type)
("chmod" . template-chmod)
("rewrite" . template-rewrite)
("export" . template-export)
("help" . template-help)))
(defun template-init (names)
@ -149,6 +150,22 @@ exec ros -Q -m roswell -N roswell -- $0 "$@"
(setf name (pop _)))
(template-attr-file name (first _) :rewrite (second _))))
(defun template-export (_)
"Export template to directory"
(let ((name (template-default))
(dst "./"))
(when (and (equal name "default") (first _))
(setf name (pop _)))
(unless (and (templates-list :filter name)
(not (equal name "default")))
(format *error-output* "template ~S can't be exported.~%" name)
(ros:quit 1))
(when (first _)
(setf dst (first _))
(unless (string= dst "/" :start1 (1- (length dst)))
(setf dst (format nil "~A/" dst))))
(template-export-files name dst)))
(defun template-help (_)
(declare (ignore _))
"Print usage and subcommands description"

View file

@ -19,6 +19,7 @@
:template-remove-file
:template-add-file
:template-attr-file
:template-export-files
:template-apply
@ -237,3 +238,16 @@
#+ros.init
(roswell.util:system "util-template")
(defun template-export-files (template-name dst)
(let ((path (first (templates-list :filter template-name))))
(when (and path (equal (pathname-type path) "asd"))
(mapc (lambda (x)
(let* ((file-name (getf x :name))
(dst-file-path (merge-pathnames file-name dst)))
(ensure-directories-exist dst-file-path)
(uiop:copy-file (template-file-path template-name file-name)
dst-file-path)))
(template-directory template-name))
(uiop:copy-file path
(merge-pathnames (format nil "~A.asd" (pathname-name path)) dst)))))