Skip to content

Commit

Permalink
add environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
draganm committed Sep 20, 2023
1 parent d24044f commit a3275de
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/dop251/goja"
"github.com/draganm/manifestor/interpolate"
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit a3275de

Please sign in to comment.