From 20a2befa3445432812cf07f5aaac07fd57d0c5dd Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Sun, 18 Dec 2022 23:05:49 -0600 Subject: [PATCH] only render template if needed i guess? --- internal/constants/constants.go | 10 +++++++++- pkg/command/help.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/constants/constants.go b/internal/constants/constants.go index f4a2215..921baa5 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -80,4 +80,12 @@ var TemplateFuncs = template.FuncMap{ } // 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 +} diff --git a/pkg/command/help.go b/pkg/command/help.go index c60e3bd..27ce81e 100644 --- a/pkg/command/help.go +++ b/pkg/command/help.go @@ -64,7 +64,7 @@ func (cmd *Command) ShowHelp(globalOptions Options, args []string) ([]byte, erro GlobalOptions: globalOptions, HTMLOutput: runtime.UnstyledHelpEnabled(), } - err := _c.TemplateCommandHelp.Execute(&buf, c) + err := _c.HelpTemplate().Execute(&buf, c) if err != nil { return nil, err }