From a3275dec44f7c7e7f6b15f85abd087618d27ff32 Mon Sep 17 00:00:00 2001 From: Dragan Milic Date: Wed, 20 Sep 2023 17:13:04 +0200 Subject: [PATCH] add environment variables --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 901d8cc..39f679e 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/dop251/goja" "github.com/draganm/manifestor/interpolate" @@ -16,7 +17,6 @@ func main() { Flags: []cli.Flag{}, Action: func(c *cli.Context) (err error) { - fmt.Println("x") manifestorDir, err := findDotManifestorDir("") if err != nil { return err @@ -32,6 +32,18 @@ func main() { encoder := yaml.NewEncoder(os.Stdout) vm := goja.New() + + env := map[string]string{} + + for _, ev := range os.Environ() { + name, value, found := strings.Cut(ev, "=") + if found { + env[name] = value + } + } + + vm.GlobalObject().Set("env", env) + vm.GlobalObject().Set("render", func(name string, values map[string]any) error { templateName := filepath.Join(manifestorDir, "templates", name) td, err := os.ReadFile(templateName)