Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:(issue_1734) Show categories for subcommands #1735

Merged
merged 2 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,48 @@ func TestApp_Run_Categories(t *testing.T) {
}
}

func TestApp_Run_SubCommand_Categories(t *testing.T) {
buf := new(bytes.Buffer)

app := &App{
Name: "categories",
HideHelp: true,
Commands: []*Command{
{
Name: "main",
Subcommands: []*Command{
{
Name: "command1",
Category: "CAT1",
},
{
Name: "command2",
Category: "CAT2",
},
{
Name: "command3",
Category: "CAT1",
},
},
},
},
Writer: buf,
}

_ = app.Run([]string{"categories", "main"})

output := buf.String()

if !strings.Contains(output, "CAT1:\n command1") {
t.Errorf("want buffer to include category %q, did not: \n%q", "CAT1:\n command1", output)
}

if !strings.Contains(output, "CAT2:\n command2") {
t.Errorf("want buffer to include category %q, did not: \n%q", "CAT2:\n command2", output)
}

}

func TestApp_VisibleCategories(t *testing.T) {
app := &App{
Name: "visible-categories",
Expand Down
2 changes: 1 addition & 1 deletion godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ USAGE:
DESCRIPTION:
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}}

COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}

OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}

Expand Down
2 changes: 1 addition & 1 deletion template.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ USAGE:
DESCRIPTION:
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}}

COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}

OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}

Expand Down
2 changes: 1 addition & 1 deletion testdata/godoc-v2.x.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ USAGE:
DESCRIPTION:
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}}

COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}

OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}

Expand Down