Fix tests
This commit is contained in:
parent
1ada1a1c06
commit
02613e50be
@ -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 [arguments...]
|
// greet describeit [command options] [arguments...]
|
||||||
//
|
//
|
||||||
// DESCRIPTION:
|
// DESCRIPTION:
|
||||||
// This is how we describe describeit the function
|
// This is how we describe describeit the function
|
||||||
|
20
category.go
20
category.go
@ -100,29 +100,15 @@ func newFlagCategories() FlagCategories {
|
|||||||
|
|
||||||
func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
|
func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
|
||||||
fc := newFlagCategories()
|
fc := newFlagCategories()
|
||||||
if !enableCategory(fs) {
|
|
||||||
return fc
|
|
||||||
}
|
|
||||||
for _, fl := range fs {
|
for _, fl := range fs {
|
||||||
if cf, ok := fl.(CategorizableFlag); ok {
|
if cf, ok := fl.(CategorizableFlag); ok {
|
||||||
fc.AddFlag(cf.GetCategory(), cf)
|
if cf.GetCategory() != "" {
|
||||||
}
|
fc.AddFlag(cf.GetCategory(), cf)
|
||||||
}
|
|
||||||
|
|
||||||
return fc
|
|
||||||
}
|
|
||||||
|
|
||||||
func enableCategory(fs []Flag) bool {
|
|
||||||
for _, fl := range fs {
|
|
||||||
if cf, ok := fl.(CategorizableFlag); ok {
|
|
||||||
// When a category is specified, it is assumed that the entire command opens the category
|
|
||||||
if len(cf.GetCategory()) != 0 {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return fc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *defaultFlagCategories) AddFlag(category string, fl Flag) {
|
func (f *defaultFlagCategories) AddFlag(category string, fl Flag) {
|
||||||
|
@ -312,7 +312,9 @@ func (c *Command) VisibleFlagCategories() []VisibleFlagCategory {
|
|||||||
c.flagCategories = newFlagCategories()
|
c.flagCategories = newFlagCategories()
|
||||||
for _, fl := range c.Flags {
|
for _, fl := range c.Flags {
|
||||||
if cf, ok := fl.(CategorizableFlag); ok {
|
if cf, ok := fl.(CategorizableFlag); ok {
|
||||||
c.flagCategories.AddFlag(cf.GetCategory(), cf)
|
if cf.GetCategory() != "" {
|
||||||
|
c.flagCategories.AddFlag(cf.GetCategory(), cf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
help.go
6
help.go
@ -242,11 +242,7 @@ 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 {
|
||||||
if c.flagCategories == nil {
|
c.appendFlag(HelpFlag)
|
||||||
c.flagCategories = newFlagCategoriesFromFlags([]Flag{HelpFlag})
|
|
||||||
} else {
|
|
||||||
c.flagCategories.AddFlag("", HelpFlag)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
templ := c.CustomHelpTemplate
|
templ := c.CustomHelpTemplate
|
||||||
if templ == "" {
|
if templ == "" {
|
||||||
|
12
help_test.go
12
help_test.go
@ -1366,7 +1366,8 @@ DESCRIPTION:
|
|||||||
case
|
case
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--help, -h show help (default: false)
|
--help, -h show help
|
||||||
|
(default: false)
|
||||||
`
|
`
|
||||||
|
|
||||||
if output.String() != expected {
|
if output.String() != expected {
|
||||||
@ -1435,7 +1436,8 @@ USAGE:
|
|||||||
even more
|
even more
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--help, -h show help (default: false)
|
--help, -h show help
|
||||||
|
(default: false)
|
||||||
`
|
`
|
||||||
|
|
||||||
if output.String() != expected {
|
if output.String() != expected {
|
||||||
@ -1510,8 +1512,10 @@ USAGE:
|
|||||||
even more
|
even more
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--help, -h show help (default: false)
|
--test-f value my test
|
||||||
--test-f value my test usage
|
usage
|
||||||
|
--help, -h show help
|
||||||
|
(default: false)
|
||||||
`
|
`
|
||||||
|
|
||||||
if output.String() != expected {
|
if output.String() != expected {
|
||||||
|
10
template.go
10
template.go
@ -18,8 +18,8 @@ var visibleFlagCategoryTemplate = `{{range .VisibleFlagCategories}}
|
|||||||
{{else}}{{$e}}
|
{{else}}{{$e}}
|
||||||
{{end}}{{end}}{{end}}`
|
{{end}}{{end}}{{end}}`
|
||||||
|
|
||||||
var visibleFlagTemplate = `{{range $index, $option := .VisibleFlags}}{{if $index}}{{end}}
|
var visibleFlagTemplate = `{{range $i, $e := .VisibleFlags}}
|
||||||
{{wrap $option.String 6}}{{end}}`
|
{{wrap $e.String 6}}{{end}}`
|
||||||
|
|
||||||
var versionTemplate = `{{if .Version}}{{if not .HideVersion}}
|
var versionTemplate = `{{if .Version}}{{if not .HideVersion}}
|
||||||
|
|
||||||
@ -73,7 +73,8 @@ DESCRIPTION:
|
|||||||
|
|
||||||
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
|
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
|
||||||
|
|
||||||
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}`
|
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
|
||||||
|
`
|
||||||
|
|
||||||
// SubcommandHelpTemplate is the text template for the subcommand help topic.
|
// SubcommandHelpTemplate is the text template for the subcommand help topic.
|
||||||
// cli.go uses text/template to render templates. You can
|
// cli.go uses text/template to render templates. You can
|
||||||
@ -91,7 +92,8 @@ COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategori
|
|||||||
|
|
||||||
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
|
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
|
||||||
|
|
||||||
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}`
|
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
|
||||||
|
`
|
||||||
|
|
||||||
var MarkdownDocTemplate = `{{if gt .SectionNum 0}}% {{ .App.Name }} {{ .SectionNum }}
|
var MarkdownDocTemplate = `{{if gt .SectionNum 0}}% {{ .App.Name }} {{ .SectionNum }}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user