Skip to content

Commit

Permalink
DXE-1304 cli RC.3
Browse files Browse the repository at this point in the history
  • Loading branch information
majakubiec committed Jul 26, 2022
2 parents 6752281 + 1b2b01d commit f13d35b
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 5 deletions.
106 changes: 104 additions & 2 deletions pkg/apphelp/help_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] <subcommand>
apphelp.test%s [global flags] test [command flags] <subcommand>
Description:
test command
Subcommands:
subcommand-no-category
Expand All @@ -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'
Expand Down
12 changes: 9 additions & 3 deletions pkg/apphelp/templates/subcommand_help.tmpl
Original file line number Diff line number Diff line change
@@ -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 "<subcommand>"}} {{blue .ArgsUsage}}

{{insertString .HelpName "[global flags]" 1 | blue}}{{if .VisibleFlags}} {{blue "[command flags]"}}{{end}} {{blue "<subcommand>"}}

{{- if .Description}}

{{yellow "Description:"}}
{{.Description -}}
{{end}}

{{- if .VisibleCommands}}

{{yellow "Subcommands:"}}
Expand Down

0 comments on commit f13d35b

Please sign in to comment.