From a14194aa33517e16dd5884625da8723c5d77acc8 Mon Sep 17 00:00:00 2001 From: Robert Liebowitz Date: Wed, 16 Oct 2019 07:57:33 -0400 Subject: [PATCH] Improve documentation for HelpPrinter/HelpPrinterCustom --- help.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/help.go b/help.go index 01c19aa..d5f1c87 100644 --- a/help.go +++ b/help.go @@ -47,13 +47,15 @@ type helpPrinter func(w io.Writer, templ string, data interface{}) // Prints help for the App or Command with custom template function. type helpPrinterCustom func(w io.Writer, templ string, data interface{}, customFunc map[string]interface{}) -// HelpPrinter is a function that writes the help output. If not set a default -// is used. The function signature is: -// func(w io.Writer, templ string, data interface{}) +// HelpPrinter is a function that writes the help output. If not set explicitly, +// this calls HelpPrinterCustom using only the default template functions. var HelpPrinter helpPrinter = printHelp -// HelpPrinterCustom is same as HelpPrinter but -// takes a custom function for template function map. +// HelpPrinterCustom is a function that writes the help output. If not set +// explicitly, a default is used. +// +// The customFuncs map will be combined with a default template.FuncMap to +// allow using arbitrary functions in template rendering. var HelpPrinterCustom helpPrinterCustom = printHelpCustom // VersionPrinter prints the version for the App @@ -240,11 +242,11 @@ func ShowCommandCompletions(ctx *Context, command string) { } -func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc map[string]interface{}) { +func printHelpCustom(out io.Writer, templ string, data interface{}, customFuncs map[string]interface{}) { funcMap := template.FuncMap{ "join": strings.Join, } - for key, value := range customFunc { + for key, value := range customFuncs { funcMap[key] = value }