about summary refs log tree commit diff
path: root/main.go
diff options
context:
space:
mode:
authorPhillip Johnsen <johphi@gmail.com>2018-05-30T19·43+0200
committerVincent Ambo <github@tazj.in>2018-06-09T17·16+0200
commit5cf9d53e80accaeede1b4e38772d7d53c0190549 (patch)
treed41b60612f1993387267c4c17085c67a18cabe4f /main.go
parent09869cf8fca09d3b1076e4ee558b8ca9fc91b733 (diff)
feat(context): allow explicit variables to be defined as argument
These changes allows variables to be defined when executing
`kontemplate` via one or more `--variable` arguments.

With this in place one can either define new variables or override
existing variables loaded from a file:

```
$ kontemplate apply --variable version=v1.0 example/fancy-app.yaml
```

This avoids the need to write variables into a temporary file that is
only needed to provide "external variables" into resource sets.

Closes https://github.com/tazjin/kontemplate/issues/122
Diffstat (limited to 'main.go')
-rw-r--r--main.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/main.go b/main.go
index 13aabd248d2d..ee70bdae55a8 100644
--- a/main.go
+++ b/main.go
@@ -37,6 +37,7 @@ var (
 	// Global flags
 	includes = app.Flag("include", "Resource sets to include explicitly").Short('i').Strings()
 	excludes = app.Flag("exclude", "Resource sets to exclude explicitly").Short('e').Strings()
+	variables = app.Flag("var", "Provide variables to templates explicitly").Strings()
 
 	// Commands
 	template          = app.Command("template", "Template resource sets and print them")
@@ -188,6 +189,11 @@ func loadContextAndResources(file *string) (*context.Context, *[]templater.Rende
 		app.Fatalf("Error loading context: %v\n", err)
 	}
 
+	err = ctx.SetVariablesFromArguments(variables)
+	if err != nil {
+		app.Fatalf("Error setting explicit variables in context: %v\n", err)
+	}
+
 	resources, err := templater.LoadAndApplyTemplates(includes, excludes, ctx)
 	if err != nil {
 		app.Fatalf("Error templating resource sets: %v\n", err)