Skip to content

Commit

Permalink
feat: export DefaultHelpFn
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
coadler committed Aug 23, 2024
1 parent 7c9fe92 commit 556f4d2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func (inv *Invocation) run(state *runState) error {

if inv.Command.Handler == nil || errors.Is(state.flagParseErr, pflag.ErrHelp) {
if inv.Command.HelpHandler == nil {
return defaultHelpFn()(inv)
return DefaultHelpFn()(inv)
}
return inv.Command.HelpHandler(inv)
}
Expand Down
4 changes: 2 additions & 2 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ func (lm *newlineLimiter) Write(p []byte) (int, error) {

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

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

0 comments on commit 556f4d2

Please sign in to comment.