setup-lisp/.github/actions/run-tests/templater.ros

41 lines
1.1 KiB
Text
Raw Normal View History

2021-02-02 08:09:28 +00:00
#!/bin/sh
#|-*- mode:lisp -*-|#
#|
2021-02-03 15:32:22 +00:00
exec ros -Q -L sbcl-bin -- $0 "$@"
2021-02-02 08:09:28 +00:00
|#
(progn
(ros:ensure-asdf)
#+quicklisp
2021-02-02 23:55:43 +00:00
(ql:quickload '(djula)
2021-02-02 08:09:28 +00:00
:silent t))
(defpackage :ros.script.templater
(:use :cl))
(in-package :ros.script.templater)
2021-02-02 23:55:43 +00:00
(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))))
2021-02-02 08:09:28 +00:00
(defun main (&rest argv)
2021-02-02 23:55:43 +00:00
(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)))
2021-02-02 08:09:28 +00:00
;;; vim: set ft=lisp lisp: