about summary refs log tree commit diff
path: root/main.go
blob: 158c9a566a86062a1f4358e7ce2b4ff13c2e84e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
	"fmt"
	"os"

	"github.com/tazjin/kontemplate/context"
	"github.com/tazjin/kontemplate/templater"
)

func main() {
	args := os.Args[1:]
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "Usage: kontemplate <cluster-config>")
		os.Exit(1)
	}

	c, err := context.LoadContextFromFile(os.Args[1])

	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(1)
	}

	fmt.Fprintf(os.Stderr, "Applying cluster %s\n", c.Name)

	for _, rs := range c.ResourceSets {
		fmt.Fprintf(os.Stderr, "Applying resource %s with values %v\n", rs.Name, rs.Values)
		resources, err := templater.LoadAndPrepareTemplates(c)

		if err != nil {
			fmt.Println(err)
		}

		for _, r := range resources {
			fmt.Print(r)
		}
	}
}