Add test case
This commit is contained in:
parent
ae8c5118f2
commit
c86805de7c
@ -177,7 +177,7 @@ func ExampleApp_Run_commandHelp() {
|
|||||||
// greet describeit - use it to see a description
|
// greet describeit - use it to see a description
|
||||||
//
|
//
|
||||||
// USAGE:
|
// USAGE:
|
||||||
// greet describeit [command options] [arguments...]
|
// greet describeit [arguments...]
|
||||||
//
|
//
|
||||||
// DESCRIPTION:
|
// DESCRIPTION:
|
||||||
// This is how we describe describeit the function
|
// This is how we describe describeit the function
|
||||||
|
6
help.go
6
help.go
@ -242,7 +242,11 @@ func ShowCommandHelp(ctx *Context, command string) error {
|
|||||||
c.Subcommands = append(c.Subcommands, helpCommandDontUse)
|
c.Subcommands = append(c.Subcommands, helpCommandDontUse)
|
||||||
}
|
}
|
||||||
if !ctx.App.HideHelp && HelpFlag != nil {
|
if !ctx.App.HideHelp && HelpFlag != nil {
|
||||||
c.appendFlag(HelpFlag)
|
if c.flagCategories == nil {
|
||||||
|
c.flagCategories = newFlagCategoriesFromFlags([]Flag{HelpFlag})
|
||||||
|
} else {
|
||||||
|
c.flagCategories.AddFlag("", HelpFlag)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
templ := c.CustomHelpTemplate
|
templ := c.CustomHelpTemplate
|
||||||
if templ == "" {
|
if templ == "" {
|
||||||
|
79
help_test.go
79
help_test.go
@ -1367,6 +1367,7 @@ DESCRIPTION:
|
|||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--help, -h show help (default: false)
|
--help, -h show help (default: false)
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
if output.String() != expected {
|
if output.String() != expected {
|
||||||
@ -1436,6 +1437,84 @@ USAGE:
|
|||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--help, -h show help (default: false)
|
--help, -h show help (default: false)
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
if output.String() != expected {
|
||||||
|
t.Errorf("Unexpected wrapping, got:\n%s\nexpected: %s",
|
||||||
|
output.String(), expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrappedHelpSubcommand(t *testing.T) {
|
||||||
|
|
||||||
|
// Reset HelpPrinter after this test.
|
||||||
|
defer func(old helpPrinter) {
|
||||||
|
HelpPrinter = old
|
||||||
|
}(HelpPrinter)
|
||||||
|
|
||||||
|
output := new(bytes.Buffer)
|
||||||
|
app := &App{
|
||||||
|
Name: "cli.test",
|
||||||
|
Writer: output,
|
||||||
|
Commands: []*Command{
|
||||||
|
{
|
||||||
|
Name: "bar",
|
||||||
|
Aliases: []string{"a"},
|
||||||
|
Usage: "add a task to the list",
|
||||||
|
UsageText: "this is an even longer way of describing adding a task to the list",
|
||||||
|
Description: "and a description long enough to wrap in this test case",
|
||||||
|
Action: func(c *Context) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Subcommands: []*Command{
|
||||||
|
{
|
||||||
|
Name: "grok",
|
||||||
|
Usage: "remove an existing template",
|
||||||
|
UsageText: "longer usage text goes here, la la la, hopefully this is long enough to wrap even more",
|
||||||
|
Action: func(c *Context) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Flags: []Flag{
|
||||||
|
&StringFlag{
|
||||||
|
Name: "test-f",
|
||||||
|
Usage: "my test usage",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
HelpPrinter = func(w io.Writer, templ string, data interface{}) {
|
||||||
|
funcMap := map[string]interface{}{
|
||||||
|
"wrapAt": func() int {
|
||||||
|
return 30
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
HelpPrinterCustom(w, templ, data, funcMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = app.Run([]string{"foo", "bar", "help", "grok"})
|
||||||
|
|
||||||
|
expected := `NAME:
|
||||||
|
cli.test bar grok - remove
|
||||||
|
an
|
||||||
|
existing
|
||||||
|
template
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
longer usage text goes
|
||||||
|
here, la la la, hopefully
|
||||||
|
this is long enough to wrap
|
||||||
|
even more
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
--help, -h show help (default: false)
|
||||||
|
--test-f value my test usage
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
if output.String() != expected {
|
if output.String() != expected {
|
||||||
|
@ -54,10 +54,10 @@ DESCRIPTION:
|
|||||||
|
|
||||||
OPTIONS:{{range .VisibleFlagCategories}}
|
OPTIONS:{{range .VisibleFlagCategories}}
|
||||||
{{if .Name}}{{.Name}}
|
{{if .Name}}{{.Name}}
|
||||||
{{end}}{{range .Flags}}{{.}}{{end}}{{end}}{{else}}{{if .VisibleFlags}}
|
{{end}}{{range .Flags}}{{.}}
|
||||||
|
{{end}}{{end}}{{else}}{{if .VisibleFlags}}
|
||||||
OPTIONS:{{range .VisibleFlags}}
|
OPTIONS:{{range $index, $option := .VisibleFlags}}{{if $index}}{{end}}
|
||||||
{{.}}{{end}}{{end}}{{end}}
|
{{wrap $option.String 6}}{{end}}{{end}}{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
// SubcommandHelpTemplate is the text template for the subcommand help topic.
|
// SubcommandHelpTemplate is the text template for the subcommand help topic.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user