Skip to content

Commit 539d63d

Browse files
authored
feat: export DefaultHelpFn (#20)
Right now, there seems to be no clear way to programmatically print the help text generated with `--help`. This exports it so you can call it at-will.
1 parent 7c9fe92 commit 539d63d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ func (inv *Invocation) run(state *runState) error {
479479

480480
if inv.Command.Handler == nil || errors.Is(state.flagParseErr, pflag.ErrHelp) {
481481
if inv.Command.HelpHandler == nil {
482-
return defaultHelpFn()(inv)
482+
return DefaultHelpFn()(inv)
483483
}
484484
return inv.Command.HelpHandler(inv)
485485
}

help.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ func (lm *newlineLimiter) Write(p []byte) (int, error) {
322322

323323
var usageWantsArgRe = regexp.MustCompile(`<.*>`)
324324

325-
// defaultHelpFn returns a function that generates usage (help)
325+
// DefaultHelpFn returns a function that generates usage (help)
326326
// output for a given command.
327-
func defaultHelpFn() HandlerFunc {
327+
func DefaultHelpFn() HandlerFunc {
328328
return func(inv *Invocation) error {
329329
// We use stdout for help and not stderr since there's no straightforward
330330
// way to distinguish between a user error and a help request.

0 commit comments

Comments
 (0)