only render template if needed i guess?

This commit is contained in:
Roberto Hidalgo 2022-12-18 23:05:49 -06:00
parent c622ba72be
commit 20a2befa34
2 changed files with 10 additions and 2 deletions

View File

@ -80,4 +80,12 @@ var TemplateFuncs = template.FuncMap{
} }
// TemplateCommandHelp holds a template for rendering command help. // TemplateCommandHelp holds a template for rendering command help.
var TemplateCommandHelp = template.Must(template.New("help").Funcs(TemplateFuncs).Parse(helpTemplateText)) var TemplateCommandHelp *template.Template
func HelpTemplate() *template.Template {
if TemplateCommandHelp == nil {
TemplateCommandHelp = template.Must(template.New("help").Funcs(TemplateFuncs).Parse(helpTemplateText))
}
return TemplateCommandHelp
}

View File

@ -64,7 +64,7 @@ func (cmd *Command) ShowHelp(globalOptions Options, args []string) ([]byte, erro
GlobalOptions: globalOptions, GlobalOptions: globalOptions,
HTMLOutput: runtime.UnstyledHelpEnabled(), HTMLOutput: runtime.UnstyledHelpEnabled(),
} }
err := _c.TemplateCommandHelp.Execute(&buf, c) err := _c.HelpTemplate().Execute(&buf, c)
if err != nil { if err != nil {
return nil, err return nil, err
} }