pass service to output fn in output-template

instead of on command line
This commit is contained in:
Daniel Barlow 2024-08-12 22:53:07 +01:00 committed by Raito Bezarius
parent 87e1fa128a
commit 1896d9d70c
12 changed files with 10 additions and 9 deletions

View file

@ -1,3 +1,3 @@
check:
./output-template ./example-output/ '{{' '}}' < example.ini > output
./output-template '{{' '}}' < example.ini > output
diff -u output example.ini.expected

View file

@ -1,3 +1,3 @@
wpa_passphrase={{ secret "colours/black" }}
think = {{ string.format("%q", secret("colours/blue")) }}
wpa_passphrase={{ output("./example-service","colours/black") }}
think = {{ string.format("%q", output("./example-service","colours/blue")) }}
argonaut = {{ json_quote "hello\ngoodbye\tnext\027" }}

View file

@ -20,11 +20,14 @@
(fn [x] (string.format "\\u%04X" (string.byte x))))))
(fn substitute [text service opening closing]
(fn substitute [text opening closing]
(let [delim (.. opening "(.-)" closing)
myenv {
: string
:secret (fn [x] (service:output x))
:output
(fn [service-path path]
(let [s (assert (svc.open (.. service-path "/.outputs")))]
(s:output path)))
:lua_quote #(string.format "%q" %1)
:json_quote (fn [x] (.. "\"" (json-escape x) "\""))
}]
@ -34,10 +37,8 @@
(string.format "missing value for %q" x))))))
(fn run []
(let [[service-dir opening closing] arg
service (assert (svc.open service-dir))
out (substitute (: (io.input) :read "*a") service opening closing)]
(let [[opening closing] arg
out (substitute (: (io.input) :read "*a") opening closing)]
(io.write out)))
{ : run }