pass service to output fn in output-template
instead of on command line
This commit is contained in:
1 parent
3c353e4aff
commit
ff3a1905a5
12 files changed
+10
-9
No files matched your search
@@ -1,3 +1,3 @@
|
||||
check:
|
||||
./output-template ./example-output/ '{{' '}}' < example.ini > output
|
||||
./output-template '{{' '}}' < example.ini > output
|
||||
diff -u output example.ini.expected
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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" }}
|
||||
@@ -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 }
|
||||
Reference in new issue
Block a user