diff --git a/pkg/apphelp/help_command_test.go b/pkg/apphelp/help_command_test.go index 2f23df4..cf50704 100644 --- a/pkg/apphelp/help_command_test.go +++ b/pkg/apphelp/help_command_test.go @@ -187,10 +187,13 @@ Global Flags: }, expectedOutput: fmt.Sprintf(` Name: - apphelp.test%s test - A new cli application + apphelp.test%s test Usage: - apphelp.test%s [global flags] test [command flags] + apphelp.test%s [global flags] test [command flags] + +Description: + test command Subcommands: subcommand-no-category @@ -204,6 +207,105 @@ category2: Command Flags: --help, -h show help (default: false) +Global Flags: + --edgerc value, -e value edgerc config path passed to executed commands, defaults to ~/.edgerc + --section value, -s value edgerc section name passed to executed commands, defaults to 'default' +`, binarySuffix, binarySuffix), + }, + + "help for subcommand no category": { + args: []string{"test", "subcommand-no-category"}, + cmd: &cli.Command{ + Name: "test", + Description: "test command", + Category: "", + Action: func(ctx *cli.Context) error { fmt.Println("oops!"); return nil }, + Subcommands: []*cli.Command{ + { + Name: "subcommand-no-category", + Description: "a test subcommand without a category", + }, + { + Name: "subcommand-with-aliases", + Description: "a test subcommand with aliases and without a category", + Aliases: []string{"sub-wa", "s-w-a"}, + }, + { + Name: "subcommand-in-category1", + Description: "a test subcommand in category 1", + Category: "category1", + }, + { + Name: "subcommand-in-category2", + Description: "a test subcommand in category 2", + Category: "category2", + }, + }, + }, + expectedOutput: fmt.Sprintf(` +Name: + apphelp.test%s test subcommand-no-category + +Usage: + apphelp.test%s [global flags] test subcommand-no-category [command flags] + +Description: + a test subcommand without a category + +Command Flags: + --help, -h show help (default: false) + +Global Flags: + --edgerc value, -e value edgerc config path passed to executed commands, defaults to ~/.edgerc + --section value, -s value edgerc section name passed to executed commands, defaults to 'default' +`, binarySuffix, binarySuffix), + }, + + "help for subcommands with category": { + args: []string{"test", "subcommand-in-category1"}, + cmd: &cli.Command{ + Name: "test", + Description: "test command", + Category: "", + Action: func(ctx *cli.Context) error { fmt.Println("oops!"); return nil }, + Subcommands: []*cli.Command{ + { + Name: "subcommand-no-category", + Description: "a test subcommand without a category", + }, + { + Name: "subcommand-with-aliases", + Description: "a test subcommand with aliases and without a category", + Aliases: []string{"sub-wa", "s-w-a"}, + }, + { + Name: "subcommand-in-category1", + Description: "a test subcommand in category 1", + Category: "category1", + }, + { + Name: "subcommand-in-category2", + Description: "a test subcommand in category 2", + Category: "category2", + }, + }, + }, + expectedOutput: fmt.Sprintf(` +Name: + apphelp.test%s test subcommand-in-category1 + +Usage: + apphelp.test%s [global flags] test subcommand-in-category1 [command flags] + +Type: + category1 + +Description: + a test subcommand in category 1 + +Command Flags: + --help, -h show help (default: false) + Global Flags: --edgerc value, -e value edgerc config path passed to executed commands, defaults to ~/.edgerc --section value, -s value edgerc section name passed to executed commands, defaults to 'default' diff --git a/pkg/apphelp/templates/subcommand_help.tmpl b/pkg/apphelp/templates/subcommand_help.tmpl index 5e3b6c0..deb5a20 100644 --- a/pkg/apphelp/templates/subcommand_help.tmpl +++ b/pkg/apphelp/templates/subcommand_help.tmpl @@ -1,10 +1,16 @@ {{with .Command -}} {{yellow "Name:"}} - {{.HelpName}} - {{.Usage}} + {{.HelpName}} {{yellow "Usage:"}} - {{insertString .HelpName "[global flags]" 1 | blue}}{{if .VisibleFlags}} {{blue "[command flags]"}}{{end}} {{blue ""}} {{blue .ArgsUsage}} - + {{insertString .HelpName "[global flags]" 1 | blue}}{{if .VisibleFlags}} {{blue "[command flags]"}}{{end}} {{blue ""}} + +{{- if .Description}} + +{{yellow "Description:"}} + {{.Description -}} +{{end}} + {{- if .VisibleCommands}} {{yellow "Subcommands:"}}