roswell.roswell/lisp/init.ros
2016-04-10 19:01:35 +09:00

58 lines
2.1 KiB
Common Lisp

#!/bin/sh
#|-*- mode:lisp -*-|#
#|Create new ros script
exec ros +Q -m roswell -L sbcl-bin -- $0 "$@"
|#
#-ros.util
(ros:include "util")
(when (cl:find-package :ros.sub.init)
(push :ros.sub.init *features*))
(defpackage :ros.sub.init
(:use :cl :ros))
(in-package :ros.sub.init)
(defun main (subcmd cmd &optional name &rest r)
(declare (ignore cmd))
(if (and (equal subcmd "main") name)
(let* ((date (get-universal-time))
(path (format nil "templates/~A/~A.asd" name name)))
(setq path (probe-file (merge-pathnames path (ros.util:homedir))))
(when path
(asdf:load-asd path)
(ql:quickload name :silent t)
(when *main*
(apply *main* r)))
(setq path (make-pathname :defaults name :type "ros"))
(handler-case
(unless
(prog1
(with-open-file (out path
:direction :output
:if-exists nil
:if-does-not-exist :create)
(when out
(format out "~@{~A~%~}"
"#!/bin/sh"
"#|-*- mode:lisp -*-|#"
"#| <Put a one-line description here>"
"exec ros -Q -- $0 \"$@\"" "|#"
(format nil "(defpackage :ros.script.~A.~A" name date)
" (:use :cl))"
(format nil "(in-package :ros.script.~A.~A)" name date)
"(defun main (&rest argv)"
" (declare (ignorable argv)))"
";;; vim: set ft=lisp lisp:")
(format t "~&Successfully generated: ~A~%" path)
t))
#+sbcl (sb-posix:chmod path #o700))
(format *error-output* "~&File already exists: ~A~%" path)
(quit -1))
(error (e)
(format *error-output* "~&~A~%" e)
(quit -1))))
()))