mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
cmd: Reuse template in helpers
This commit is contained in:
parent
0dd1c429a3
commit
66cfd1f132
1 changed files with 4 additions and 5 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue