Skip to content

Commit 9cd5d9c

Browse files
authored
Merge pull request #2150 from almas-x/main
Export help display functions as variables to allow custom help display logic
2 parents d341030 + 23a9ea8 commit 9cd5d9c

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

godoc-current.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ COPYRIGHT:
131131
cli.go uses text/template to render templates. You can render custom help
132132
text by setting this variable.
133133

134+
var ShowAppHelp = showAppHelp
135+
ShowAppHelp is an action that displays the help
136+
137+
var ShowCommandHelp = showCommandHelp
138+
ShowCommandHelp prints help for the given command
139+
140+
var ShowSubcommandHelp = showSubcommandHelp
141+
ShowSubcommandHelp prints help for the given subcommand
142+
134143
var SubcommandHelpTemplate = `NAME:
135144
{{template "helpNameTemplate" .}}
136145

@@ -195,22 +204,13 @@ func HandleExitCoder(err error)
195204

196205
This function is the default error-handling behavior for an App.
197206

198-
func ShowAppHelp(cmd *Command) error
199-
ShowAppHelp is an action that displays the help.
200-
201207
func ShowAppHelpAndExit(cmd *Command, exitCode int)
202208
ShowAppHelpAndExit - Prints the list of subcommands for the app and exits
203209
with exit code.
204210

205-
func ShowCommandHelp(ctx context.Context, cmd *Command, commandName string) error
206-
ShowCommandHelp prints help for the given command
207-
208211
func ShowCommandHelpAndExit(ctx context.Context, cmd *Command, command string, code int)
209212
ShowCommandHelpAndExit - exits with code after showing help
210213

211-
func ShowSubcommandHelp(cmd *Command) error
212-
ShowSubcommandHelp prints help for the given subcommand
213-
214214
func ShowSubcommandHelpAndExit(cmd *Command, exitCode int)
215215
ShowSubcommandHelpAndExit - Prints help for the given subcommand and exits
216216
with exit code.

help.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ var HelpPrinterCustom helpPrinterCustom = printHelpCustom
4444
// VersionPrinter prints the version for the App
4545
var VersionPrinter = printVersion
4646

47+
// ShowAppHelp is an action that displays the help
48+
var ShowAppHelp = showAppHelp
49+
50+
// ShowCommandHelp prints help for the given command
51+
var ShowCommandHelp = showCommandHelp
52+
53+
// ShowSubcommandHelp prints help for the given subcommand
54+
var ShowSubcommandHelp = showSubcommandHelp
55+
4756
func buildHelpCommand(withAction bool) *Command {
4857
cmd := &Command{
4958
Name: helpName,
@@ -131,7 +140,7 @@ func ShowAppHelpAndExit(cmd *Command, exitCode int) {
131140
}
132141

133142
// ShowAppHelp is an action that displays the help.
134-
func ShowAppHelp(cmd *Command) error {
143+
func showAppHelp(cmd *Command) error {
135144
tmpl := cmd.CustomRootCommandHelpTemplate
136145
if tmpl == "" {
137146
tracef("using RootCommandHelpTemplate")
@@ -270,8 +279,7 @@ func ShowCommandHelpAndExit(ctx context.Context, cmd *Command, command string, c
270279
os.Exit(code)
271280
}
272281

273-
// ShowCommandHelp prints help for the given command
274-
func ShowCommandHelp(ctx context.Context, cmd *Command, commandName string) error {
282+
func showCommandHelp(ctx context.Context, cmd *Command, commandName string) error {
275283
for _, subCmd := range cmd.Commands {
276284
if !subCmd.HasName(commandName) {
277285
continue
@@ -322,8 +330,7 @@ func ShowSubcommandHelpAndExit(cmd *Command, exitCode int) {
322330
os.Exit(exitCode)
323331
}
324332

325-
// ShowSubcommandHelp prints help for the given subcommand
326-
func ShowSubcommandHelp(cmd *Command) error {
333+
func showSubcommandHelp(cmd *Command) error {
327334
HelpPrinter(cmd.Root().Writer, SubcommandHelpTemplate, cmd)
328335
return nil
329336
}

testdata/godoc-v3.x.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ COPYRIGHT:
131131
cli.go uses text/template to render templates. You can render custom help
132132
text by setting this variable.
133133

134+
var ShowAppHelp = showAppHelp
135+
ShowAppHelp is an action that displays the help
136+
137+
var ShowCommandHelp = showCommandHelp
138+
ShowCommandHelp prints help for the given command
139+
140+
var ShowSubcommandHelp = showSubcommandHelp
141+
ShowSubcommandHelp prints help for the given subcommand
142+
134143
var SubcommandHelpTemplate = `NAME:
135144
{{template "helpNameTemplate" .}}
136145

@@ -195,22 +204,13 @@ func HandleExitCoder(err error)
195204

196205
This function is the default error-handling behavior for an App.
197206

198-
func ShowAppHelp(cmd *Command) error
199-
ShowAppHelp is an action that displays the help.
200-
201207
func ShowAppHelpAndExit(cmd *Command, exitCode int)
202208
ShowAppHelpAndExit - Prints the list of subcommands for the app and exits
203209
with exit code.
204210

205-
func ShowCommandHelp(ctx context.Context, cmd *Command, commandName string) error
206-
ShowCommandHelp prints help for the given command
207-
208211
func ShowCommandHelpAndExit(ctx context.Context, cmd *Command, command string, code int)
209212
ShowCommandHelpAndExit - exits with code after showing help
210213

211-
func ShowSubcommandHelp(cmd *Command) error
212-
ShowSubcommandHelp prints help for the given subcommand
213-
214214
func ShowSubcommandHelpAndExit(cmd *Command, exitCode int)
215215
ShowSubcommandHelpAndExit - Prints help for the given subcommand and exits
216216
with exit code.

0 commit comments

Comments
 (0)