From 66cfd1f132f9b7a2d7856f9e58a35047c3e4709d Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Sat, 29 Apr 2017 15:54:32 +0200 Subject: [PATCH] cmd: Reuse template in helpers --- cobra/cmd/helpers.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cobra/cmd/helpers.go b/cobra/cmd/helpers.go index e7ae808..d5ee906 100644 --- a/cobra/cmd/helpers.go +++ b/cobra/cmd/helpers.go @@ -23,10 +23,6 @@ import ( "text/template" ) -var funcMap = template.FuncMap{ - "comment": commentifyString, -} - var projectPath string var cmdDirs = [...]string{"cmd", "cmds", "command", "commands"} @@ -87,8 +83,11 @@ func exists(path string) bool { return false } +var tmpl = template.New("").Funcs(template.FuncMap{"comment": commentifyString}) + func executeTemplate(tmplStr string, data interface{}) (string, error) { - tmpl, err := template.New("").Funcs(funcMap).Parse(tmplStr) + var err error + tmpl, err = tmpl.Parse(tmplStr) if err != nil { return "", err }