Skip to content

Add support for best command in help #20

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

Merged
merged 1 commit into from
Aug 27, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion help.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func ShowAppHelp(c *Context) error {

// ShowCommandHelp prints help for the given command
func ShowCommandHelp(ctx *Context, command string) error {
if c := ctx.App.Command(command); c != nil {
if c := ctx.App.BestCommand(command); c != nil {
if c.DescriptionFunc != nil {
c.Description = c.DescriptionFunc(c, ctx.App)
}
Expand Down
23 changes: 23 additions & 0 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,29 @@ func TestShowCommandHelp_CommandAliases(t *testing.T) {
}
}

func TestShowCommandHelp_CommandShortcut(t *testing.T) {
app := &Application{
Commands: []*Command{
{
Name: "bar",
Category: "foo",
Aliases: []*Alias{{Name: "fb"}},
Action: func(ctx *Context) error {
return nil
},
},
},
}

output := &bytes.Buffer{}
app.Writer = output
app.Run([]string{"foo", "help", "f:b"})

if !strings.Contains(output.String(), "foo:bar") {
t.Errorf("expected output to include command name; got: %q", output.String())
}
}

func TestShowCommandHelp_DescriptionFunc(t *testing.T) {
app := &Application{
Commands: []*Command{
Expand Down
Loading