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-06 12:46:31 +00:00
|
|
|
(defun interpose (separator list)
|
|
|
|
"Returns a sequence of the elements of SEQUENCE separated by SEPARATOR."
|
|
|
|
(labels ((rec (s acc)
|
|
|
|
(if s
|
|
|
|
(rec (cdr s) (nconc acc
|
|
|
|
(list separator (car s))))
|
|
|
|
acc)))
|
|
|
|
(cdr (rec list nil))))
|
|
|
|
|
|
|
|
|
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*))
|
2021-02-06 12:46:31 +00:00
|
|
|
(template-text (apply #'concatenate 'string
|
|
|
|
(interpose (string #\Newline)
|
|
|
|
lines)))
|
2021-02-02 23:55:43 +00:00
|
|
|
(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:
|