Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Oct 7, 2022
1 parent 1ada1a1 commit 02613e5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app_test.go
Expand Up @@ -177,7 +177,7 @@ func ExampleApp_Run_commandHelp() {
// greet describeit - use it to see a description
//
// USAGE:
// greet describeit [arguments...]
// greet describeit [command options] [arguments...]
//
// DESCRIPTION:
// This is how we describe describeit the function
Expand Down
20 changes: 3 additions & 17 deletions category.go
Expand Up @@ -100,29 +100,15 @@ func newFlagCategories() FlagCategories {

func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
fc := newFlagCategories()
if !enableCategory(fs) {
return fc
}
for _, fl := range fs {
if cf, ok := fl.(CategorizableFlag); ok {
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
if cf.GetCategory() != "" {
fc.AddFlag(cf.GetCategory(), cf)
}
}
}

return false
return fc
}

func (f *defaultFlagCategories) AddFlag(category string, fl Flag) {
Expand Down
4 changes: 3 additions & 1 deletion command.go
Expand Up @@ -312,7 +312,9 @@ func (c *Command) VisibleFlagCategories() []VisibleFlagCategory {
c.flagCategories = newFlagCategories()
for _, fl := range c.Flags {
if cf, ok := fl.(CategorizableFlag); ok {
c.flagCategories.AddFlag(cf.GetCategory(), cf)
if cf.GetCategory() != "" {
c.flagCategories.AddFlag(cf.GetCategory(), cf)
}
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions help.go
Expand Up @@ -242,11 +242,7 @@ func ShowCommandHelp(ctx *Context, command string) error {
c.Subcommands = append(c.Subcommands, helpCommandDontUse)
}
if !ctx.App.HideHelp && HelpFlag != nil {
if c.flagCategories == nil {
c.flagCategories = newFlagCategoriesFromFlags([]Flag{HelpFlag})
} else {
c.flagCategories.AddFlag("", HelpFlag)
}
c.appendFlag(HelpFlag)
}
templ := c.CustomHelpTemplate
if templ == "" {
Expand Down
12 changes: 8 additions & 4 deletions help_test.go
Expand Up @@ -1366,7 +1366,8 @@ DESCRIPTION:
case
OPTIONS:
--help, -h show help (default: false)
--help, -h show help
(default: false)
`

if output.String() != expected {
Expand Down Expand Up @@ -1435,7 +1436,8 @@ USAGE:
even more
OPTIONS:
--help, -h show help (default: false)
--help, -h show help
(default: false)
`

if output.String() != expected {
Expand Down Expand Up @@ -1510,8 +1512,10 @@ USAGE:
even more
OPTIONS:
--help, -h show help (default: false)
--test-f value my test usage
--test-f value my test
usage
--help, -h show help
(default: false)
`

if output.String() != expected {
Expand Down
10 changes: 6 additions & 4 deletions template.go
Expand Up @@ -18,8 +18,8 @@ var visibleFlagCategoryTemplate = `{{range .VisibleFlagCategories}}
{{else}}{{$e}}
{{end}}{{end}}{{end}}`

var visibleFlagTemplate = `{{range $index, $option := .VisibleFlags}}{{if $index}}{{end}}
{{wrap $option.String 6}}{{end}}`
var visibleFlagTemplate = `{{range $i, $e := .VisibleFlags}}
{{wrap $e.String 6}}{{end}}`

var versionTemplate = `{{if .Version}}{{if not .HideVersion}}
Expand Down Expand Up @@ -73,7 +73,8 @@ DESCRIPTION:
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}`
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
`

// SubcommandHelpTemplate is the text template for the subcommand help topic.
// cli.go uses text/template to render templates. You can
Expand All @@ -91,7 +92,8 @@ COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategori
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}`
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
`

var MarkdownDocTemplate = `{{if gt .SectionNum 0}}% {{ .App.Name }} {{ .SectionNum }}
Expand Down

0 comments on commit 02613e5

Please sign in to comment.