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_1787) Add fix for commands not listed when hide help comma… #1788

Merged
merged 2 commits into from
Jul 1, 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.
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 @@ -69,7 +69,7 @@ var helpCommand = &Command{
}

// Case 3, 5
if (len(cCtx.Command.Subcommands) == 1 && !cCtx.Command.HideHelp) ||
if (len(cCtx.Command.Subcommands) == 1 && !cCtx.Command.HideHelp && !cCtx.Command.HideHelpCommand) ||
(len(cCtx.Command.Subcommands) == 0 && cCtx.Command.HideHelp) {
templ := cCtx.Command.CustomHelpTemplate
if templ == "" {
Expand Down
17 changes: 17 additions & 0 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,12 @@ func TestHelpNameConsistency(t *testing.T) {
// and SubcommandHelp templates to display the help name
// The inconsistency shows up when users use NewApp() as opposed to
// using App{...} directly
tmpTemplate := SubcommandHelpTemplate
SubcommandHelpTemplate = `{{.HelpName}}`
defer func() {
SubcommandHelpTemplate = tmpTemplate
}()

app := NewApp()
app.Name = "bar"
app.CustomAppHelpTemplate = `{{.HelpName}}`
Expand Down Expand Up @@ -1124,6 +1129,18 @@ func TestHideHelpCommand_WithSubcommands(t *testing.T) {
if err != nil {
t.Errorf("Run returned unexpected error: %v", err)
}

var buf bytes.Buffer
app.Writer = &buf

err = app.Run([]string{"foo", "dummy"})
if err != nil {
t.Errorf("Run returned unexpected error: %v", err)
}

if !strings.Contains(buf.String(), "dummy2") {
t.Errorf("Expected out to contain \"dummy2\" %v", buf.String())
}
}

func TestHideHelpCommand_RunAsSubcommand_True_CustomTemplate(t *testing.T) {
Expand Down