Improve documentation for HelpPrinter/HelpPrinterCustom
This commit is contained in:
parent
b52cca036a
commit
a14194aa33
16
help.go
16
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.
|
// 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{})
|
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
|
// HelpPrinter is a function that writes the help output. If not set explicitly,
|
||||||
// is used. The function signature is:
|
// this calls HelpPrinterCustom using only the default template functions.
|
||||||
// func(w io.Writer, templ string, data interface{})
|
|
||||||
var HelpPrinter helpPrinter = printHelp
|
var HelpPrinter helpPrinter = printHelp
|
||||||
|
|
||||||
// HelpPrinterCustom is same as HelpPrinter but
|
// HelpPrinterCustom is a function that writes the help output. If not set
|
||||||
// takes a custom function for template function map.
|
// 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
|
var HelpPrinterCustom helpPrinterCustom = printHelpCustom
|
||||||
|
|
||||||
// VersionPrinter prints the version for the App
|
// 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{
|
funcMap := template.FuncMap{
|
||||||
"join": strings.Join,
|
"join": strings.Join,
|
||||||
}
|
}
|
||||||
for key, value := range customFunc {
|
for key, value := range customFuncs {
|
||||||
funcMap[key] = value
|
funcMap[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user