@@ -428,6 +428,58 @@ func TestShowCommandHelp_CommandAliases(t *testing.T) {
428
428
}
429
429
}
430
430
431
+ func TestHelpNameConsistency (t * testing.T ) {
432
+ // Setup some very basic templates based on actual AppHelp, CommandHelp
433
+ // and SubcommandHelp templates to display the help name
434
+ // The inconsistency shows up when users use NewApp() as opposed to
435
+ // using App{...} directly
436
+ SubcommandHelpTemplate = `{{.HelpName}}`
437
+ app := NewApp ()
438
+ app .Name = "bar"
439
+ app .CustomAppHelpTemplate = `{{.HelpName}}`
440
+ app .Commands = []* Command {
441
+ {
442
+ Name : "command1" ,
443
+ CustomHelpTemplate : `{{.HelpName}}` ,
444
+ Subcommands : []* Command {
445
+ {
446
+ Name : "subcommand1" ,
447
+ CustomHelpTemplate : `{{.HelpName}}` ,
448
+ },
449
+ },
450
+ },
451
+ }
452
+
453
+ tests := []struct {
454
+ name string
455
+ args []string
456
+ }{
457
+ {
458
+ name : "App help" ,
459
+ args : []string {"foo" },
460
+ },
461
+ {
462
+ name : "Command help" ,
463
+ args : []string {"foo" , "command1" },
464
+ },
465
+ {
466
+ name : "Subcommand help" ,
467
+ args : []string {"foo" , "command1" , "subcommand1" },
468
+ },
469
+ }
470
+
471
+ for _ , tt := range tests {
472
+ output := & bytes.Buffer {}
473
+ app .Writer = output
474
+ if err := app .Run (tt .args ); err != nil {
475
+ t .Error (err )
476
+ }
477
+ if ! strings .Contains (output .String (), "bar" ) {
478
+ t .Errorf ("expected output to contain bar; got: %q" , output .String ())
479
+ }
480
+ }
481
+ }
482
+
431
483
func TestShowSubcommandHelp_CommandAliases (t * testing.T ) {
432
484
app := & App {
433
485
Commands : []* Command {
0 commit comments