From 556f4d27e1757ad92a514eaf841985838e07b93a Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Fri, 23 Aug 2024 18:09:23 +0000 Subject: [PATCH] feat: export `DefaultHelpFn` 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. --- command.go | 2 +- help.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/command.go b/command.go index 9d10dfe..9cf25ea 100644 --- a/command.go +++ b/command.go @@ -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) } diff --git a/help.go b/help.go index 533be11..207c965 100644 --- a/help.go +++ b/help.go @@ -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.