Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: urfave/cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.16.1
Choose a base ref
...
head repository: urfave/cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.16.2
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Sep 11, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    kzaher Krunoslav Zaher
    Copy the full SHA
    8339b59 View commit details
  2. Merge pull request #1489 from dearchap/fix_help_name_consistency

    Fix: Help name consistency among app/commands and subcommands
    dearchap authored Sep 11, 2022
    Copy the full SHA
    375e5df View commit details
Showing with 52 additions and 1 deletion.
  1. +0 −1 app.go
  2. +52 −0 help_test.go
1 change: 0 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
@@ -133,7 +133,6 @@ func compileTime() time.Time {
func NewApp() *App {
return &App{
Name: filepath.Base(os.Args[0]),
HelpName: filepath.Base(os.Args[0]),
Usage: "A new cli application",
UsageText: "",
BashComplete: DefaultAppComplete,
52 changes: 52 additions & 0 deletions help_test.go
Original file line number Diff line number Diff line change
@@ -428,6 +428,58 @@ func TestShowCommandHelp_CommandAliases(t *testing.T) {
}
}

func TestHelpNameConsistency(t *testing.T) {
// Setup some very basic templates based on actual AppHelp, CommandHelp
// and SubcommandHelp templates to display the help name
// The inconsistency shows up when users use NewApp() as opposed to
// using App{...} directly
SubcommandHelpTemplate = `{{.HelpName}}`
app := NewApp()
app.Name = "bar"
app.CustomAppHelpTemplate = `{{.HelpName}}`
app.Commands = []*Command{
{
Name: "command1",
CustomHelpTemplate: `{{.HelpName}}`,
Subcommands: []*Command{
{
Name: "subcommand1",
CustomHelpTemplate: `{{.HelpName}}`,
},
},
},
}

tests := []struct {
name string
args []string
}{
{
name: "App help",
args: []string{"foo"},
},
{
name: "Command help",
args: []string{"foo", "command1"},
},
{
name: "Subcommand help",
args: []string{"foo", "command1", "subcommand1"},
},
}

for _, tt := range tests {
output := &bytes.Buffer{}
app.Writer = output
if err := app.Run(tt.args); err != nil {
t.Error(err)
}
if !strings.Contains(output.String(), "bar") {
t.Errorf("expected output to contain bar; got: %q", output.String())
}
}
}

func TestShowSubcommandHelp_CommandAliases(t *testing.T) {
app := &App{
Commands: []*Command{