MCPcopy
hub / github.com/urfave/cli / DefaultPrintHelpCustom

Function DefaultPrintHelpCustom

help.go:376–463  ·  help.go::DefaultPrintHelpCustom

DefaultPrintHelpCustom is the default implementation of HelpPrinterCustom. The customFuncs map will be combined with a default template.FuncMap to allow using arbitrary functions in template rendering.

(out io.Writer, templ string, data any, customFuncs map[string]any)

Source from the content-addressed store, hash-verified

374// The customFuncs map will be combined with a default template.FuncMap to
375// allow using arbitrary functions in template rendering.
376func DefaultPrintHelpCustom(out io.Writer, templ string, data any, customFuncs map[string]any) {
377 const maxLineLength = 10000
378
379 tracef("building default funcMap")
380 funcMap := template.FuncMap{
381 "join": strings.Join,
382 "subtract": subtract,
383 "indent": indent,
384 "nindent": nindent,
385 "trim": strings.TrimSpace,
386 "wrap": func(input string, offset int) string { return wrap(input, offset, maxLineLength) },
387 "offset": offset,
388 "offsetCommands": offsetCommands,
389 }
390
391 if wa, ok := customFuncs["wrapAt"]; ok {
392 if wrapAtFunc, ok := wa.(func() int); ok {
393 wrapAt := wrapAtFunc()
394 customFuncs["wrap"] = func(input string, offset int) string {
395 return wrap(input, offset, wrapAt)
396 }
397 }
398 }
399
400 for key, value := range customFuncs {
401 funcMap[key] = value
402 }
403
404 w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0)
405 t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
406
407 if _, err := t.New("helpNameTemplate").Parse(helpNameTemplate); err != nil {
408 handleTemplateError(err)
409 }
410
411 if _, err := t.New("argsTemplate").Parse(argsTemplate); err != nil {
412 handleTemplateError(err)
413 }
414
415 if _, err := t.New("usageTemplate").Parse(usageTemplate); err != nil {
416 handleTemplateError(err)
417 }
418
419 if _, err := t.New("descriptionTemplate").Parse(descriptionTemplate); err != nil {
420 handleTemplateError(err)
421 }
422
423 if _, err := t.New("visibleCommandTemplate").Parse(visibleCommandTemplate); err != nil {
424 handleTemplateError(err)
425 }
426
427 if _, err := t.New("copyrightTemplate").Parse(copyrightTemplate); err != nil {
428 handleTemplateError(err)
429 }
430
431 if _, err := t.New("versionTemplate").Parse(versionTemplate); err != nil {
432 handleTemplateError(err)
433 }

Calls 4

tracefFunction · 0.85
wrapFunction · 0.85
handleTemplateErrorFunction · 0.85
ParseMethod · 0.65