From ba8fc3d200e5ccaf6483994f7b45cbad9a76e071 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 13 Oct 2024 21:26:09 -0400 Subject: [PATCH] Use usage template in subcommand help to remove (confusing) difference between templates. Closes #1879 --- app_test.go | 2 +- godoc-current.txt | 5 ++++- help.go | 2 +- template.go | 5 ++++- testdata/godoc-v2.x.txt | 7 +++++-- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app_test.go b/app_test.go index 1c444ec926..f6f9158b05 100644 --- a/app_test.go +++ b/app_test.go @@ -2047,7 +2047,7 @@ func TestApp_Run_CommandSubcommandHelpName(t *testing.T) { t.Errorf("expected %q in output: %q", expected, output) } - expected = "base foo command [command options] [arguments...]" + expected = "base foo [command options] [arguments...]" if !strings.Contains(output, expected) { t.Errorf("expected %q in output: %q", expected, output) } diff --git a/godoc-current.txt b/godoc-current.txt index 3e29faabac..2f3d76e319 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -136,7 +136,10 @@ var SubcommandHelpTemplate = `NAME: {{template "helpNameTemplate" .}} USAGE: - {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}command [command options]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Args}} [arguments...]{{end}}{{end}}{{end}}{{if .Description}} + {{template "usageTemplate" .}}{{if .Category}} + +CATEGORY: + {{.Category}}{{end}}{{if .Description}} DESCRIPTION: {{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}} diff --git a/help.go b/help.go index f1b9e7f18f..d27e8ce385 100644 --- a/help.go +++ b/help.go @@ -54,7 +54,7 @@ var helpCommand = &Command{ cCtx = cCtx.parentContext } - // Case 4. $ app hello foo + // Case 4. $ app help foo // foo is the command for which help needs to be shown if argsPresent { return ShowCommandHelp(cCtx, firstArg) diff --git a/template.go b/template.go index 8abc5ba421..ccb22f1d53 100644 --- a/template.go +++ b/template.go @@ -83,7 +83,10 @@ var SubcommandHelpTemplate = `NAME: {{template "helpNameTemplate" .}} USAGE: - {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}command [command options]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Args}} [arguments...]{{end}}{{end}}{{end}}{{if .Description}} + {{template "usageTemplate" .}}{{if .Category}} + +CATEGORY: + {{.Category}}{{end}}{{if .Description}} DESCRIPTION: {{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}} diff --git a/testdata/godoc-v2.x.txt b/testdata/godoc-v2.x.txt index 4b620feeb0..2f3d76e319 100644 --- a/testdata/godoc-v2.x.txt +++ b/testdata/godoc-v2.x.txt @@ -35,7 +35,7 @@ var AppHelpTemplate = `NAME: {{template "helpNameTemplate" .}} USAGE: - {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} + {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Args}} [arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} VERSION: {{.Version}}{{end}}{{end}}{{if .Description}} @@ -136,7 +136,10 @@ var SubcommandHelpTemplate = `NAME: {{template "helpNameTemplate" .}} USAGE: - {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}{{end}}{{end}}{{if .Description}} + {{template "usageTemplate" .}}{{if .Category}} + +CATEGORY: + {{.Category}}{{end}}{{if .Description}} DESCRIPTION: {{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}}