From 7ff174a86a935191a684f0c63f9e2a48058fabfb Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Mon, 11 Nov 2019 16:03:16 -0500 Subject: Support a config file to use instead of commandline arguments Signed-off-by: Dave Henderson --- context.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'context.go') diff --git a/context.go b/context.go index ab12d404..a2b8b002 100644 --- a/context.go +++ b/context.go @@ -1,10 +1,12 @@ package gomplate import ( + "context" "os" "strings" "github.com/hairyhenderson/gomplate/v3/data" + "github.com/hairyhenderson/gomplate/v3/internal/config" ) // context for templates @@ -20,11 +22,10 @@ func (c *tmplctx) Env() map[string]string { return env } -func createTmplContext(contexts []string, d *data.Data) (interface{}, error) { +func createTmplContext(ctx context.Context, contexts config.DSources, d *data.Data) (interface{}, error) { var err error tctx := &tmplctx{} - for _, c := range contexts { - a := parseAlias(c) + for a := range contexts { if a == "." { return d.Datasource(a) } @@ -35,13 +36,3 @@ func createTmplContext(contexts []string, d *data.Data) (interface{}, error) { } return tctx, nil } - -func parseAlias(arg string) string { - parts := strings.SplitN(arg, "=", 2) - switch len(parts) { - case 1: - return strings.SplitN(parts[0], ".", 2)[0] - default: - return parts[0] - } -} -- cgit v1.2.3