setup-lisp/.github/actions/scripts/templater.ros
2021-02-06 13:05:40 +03:00

40 lines
1.1 KiB
Common Lisp
Executable file

#!/bin/sh
#|-*- mode:lisp -*-|#
#|
exec ros -Q -L sbcl-bin -- $0 "$@"
|#
(progn
(ros:ensure-asdf)
#+quicklisp
(ql:quickload '(djula)
:silent t))
(defpackage :ros.script.templater
(:use :cl))
(in-package :ros.script.templater)
(defun collect-arguments ()
(let* ((env-output (with-output-to-string (s)
(uiop:run-program "env" :output s)))
(lines (uiop:with-input (env-output)
(uiop:slurp-stream-lines env-output))))
(loop for line in lines
for (key value) = (cl-ppcre:split "=" line
:limit 2)
appending (list (alexandria:make-keyword key)
value))))
(defun main (&rest argv)
(declare (ignore argv))
(let* ((lines (uiop:slurp-stream-lines *standard-input*))
(template-text (apply #'concatenate 'string lines))
(template (djula::compile-string template-text))
(arguments (collect-arguments)))
(apply #'djula:render-template*
template
*standard-output*
arguments)))
;;; vim: set ft=lisp lisp: