From 1896d9d70cb7162d0a23ae5c320a6fb6f16414d5 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 12 Aug 2024 22:53:07 +0100 Subject: [PATCH] pass service to `output` fn in output-template instead of on command line --- pkgs/output-template/Makefile | 2 +- .../.outputs}/addresses/1/attribute | 0 .../.outputs}/addresses/3/attribute | 0 .../.outputs}/addresses/5/attribute | 0 .../.outputs}/addresses/6/attribute | 0 .../.outputs}/colours/black | 0 .../.outputs}/colours/blue | 0 .../.outputs}/colours/green | 0 .../.outputs}/colours/red | 0 .../.outputs}/name | 0 pkgs/output-template/example.ini | 4 ++-- pkgs/output-template/output-template.fnl | 13 +++++++------ 12 files changed, 10 insertions(+), 9 deletions(-) rename pkgs/output-template/{example-output => example-service/.outputs}/addresses/1/attribute (100%) rename pkgs/output-template/{example-output => example-service/.outputs}/addresses/3/attribute (100%) rename pkgs/output-template/{example-output => example-service/.outputs}/addresses/5/attribute (100%) rename pkgs/output-template/{example-output => example-service/.outputs}/addresses/6/attribute (100%) rename pkgs/output-template/{example-output => example-service/.outputs}/colours/black (100%) rename pkgs/output-template/{example-output => example-service/.outputs}/colours/blue (100%) rename pkgs/output-template/{example-output => example-service/.outputs}/colours/green (100%) rename pkgs/output-template/{example-output => example-service/.outputs}/colours/red (100%) rename pkgs/output-template/{example-output => example-service/.outputs}/name (100%) diff --git a/pkgs/output-template/Makefile b/pkgs/output-template/Makefile index 1623f8a..b0d6b6c 100644 --- a/pkgs/output-template/Makefile +++ b/pkgs/output-template/Makefile @@ -1,3 +1,3 @@ check: - ./output-template ./example-output/ '{{' '}}' < example.ini > output + ./output-template '{{' '}}' < example.ini > output diff -u output example.ini.expected diff --git a/pkgs/output-template/example-output/addresses/1/attribute b/pkgs/output-template/example-service/.outputs/addresses/1/attribute similarity index 100% rename from pkgs/output-template/example-output/addresses/1/attribute rename to pkgs/output-template/example-service/.outputs/addresses/1/attribute diff --git a/pkgs/output-template/example-output/addresses/3/attribute b/pkgs/output-template/example-service/.outputs/addresses/3/attribute similarity index 100% rename from pkgs/output-template/example-output/addresses/3/attribute rename to pkgs/output-template/example-service/.outputs/addresses/3/attribute diff --git a/pkgs/output-template/example-output/addresses/5/attribute b/pkgs/output-template/example-service/.outputs/addresses/5/attribute similarity index 100% rename from pkgs/output-template/example-output/addresses/5/attribute rename to pkgs/output-template/example-service/.outputs/addresses/5/attribute diff --git a/pkgs/output-template/example-output/addresses/6/attribute b/pkgs/output-template/example-service/.outputs/addresses/6/attribute similarity index 100% rename from pkgs/output-template/example-output/addresses/6/attribute rename to pkgs/output-template/example-service/.outputs/addresses/6/attribute diff --git a/pkgs/output-template/example-output/colours/black b/pkgs/output-template/example-service/.outputs/colours/black similarity index 100% rename from pkgs/output-template/example-output/colours/black rename to pkgs/output-template/example-service/.outputs/colours/black diff --git a/pkgs/output-template/example-output/colours/blue b/pkgs/output-template/example-service/.outputs/colours/blue similarity index 100% rename from pkgs/output-template/example-output/colours/blue rename to pkgs/output-template/example-service/.outputs/colours/blue diff --git a/pkgs/output-template/example-output/colours/green b/pkgs/output-template/example-service/.outputs/colours/green similarity index 100% rename from pkgs/output-template/example-output/colours/green rename to pkgs/output-template/example-service/.outputs/colours/green diff --git a/pkgs/output-template/example-output/colours/red b/pkgs/output-template/example-service/.outputs/colours/red similarity index 100% rename from pkgs/output-template/example-output/colours/red rename to pkgs/output-template/example-service/.outputs/colours/red diff --git a/pkgs/output-template/example-output/name b/pkgs/output-template/example-service/.outputs/name similarity index 100% rename from pkgs/output-template/example-output/name rename to pkgs/output-template/example-service/.outputs/name diff --git a/pkgs/output-template/example.ini b/pkgs/output-template/example.ini index c53dea9..c968fce 100644 --- a/pkgs/output-template/example.ini +++ b/pkgs/output-template/example.ini @@ -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" }} diff --git a/pkgs/output-template/output-template.fnl b/pkgs/output-template/output-template.fnl index 0d0da28..95be3c6 100644 --- a/pkgs/output-template/output-template.fnl +++ b/pkgs/output-template/output-template.fnl @@ -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 }