-
Notifications
You must be signed in to change notification settings - Fork 3
/
templater.ros
executable file
·52 lines (44 loc) · 1.51 KB
/
templater.ros
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/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 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))))
(defun main (&rest argv)
(declare (ignore argv))
(let* ((lines (uiop:slurp-stream-lines *standard-input*))
(template-text (apply #'concatenate 'string
(interpose (string #\Newline)
lines)))
(template (djula::compile-string template-text))
(arguments (collect-arguments)))
(apply #'djula:render-template*
template
*standard-output*
arguments)))
;;; vim: set ft=lisp lisp: