Skip to content

Commit

Permalink
Merge pull request #1868 from dearchap/issue_1860
Browse files Browse the repository at this point in the history
Fix:(issue_1860) Remove hidden flags from flag categories
  • Loading branch information
dearchap committed Feb 19, 2024
2 parents 09c3974 + 64b40d2 commit 8728c19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions category.go
Expand Up @@ -104,7 +104,7 @@ func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
var categorized bool
for _, fl := range fs {
if cf, ok := fl.(CategorizableFlag); ok {
if cat := cf.GetCategory(); cat != "" {
if cat := cf.GetCategory(); cat != "" && cf.IsVisible() {
fc.AddFlag(cat, cf)
categorized = true
}
Expand All @@ -114,7 +114,7 @@ func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
if categorized {
for _, fl := range fs {
if cf, ok := fl.(CategorizableFlag); ok {
if cf.GetCategory() == "" {
if cf.GetCategory() == "" && cf.IsVisible() {
fc.AddFlag("", fl)
}
}
Expand Down
9 changes: 9 additions & 0 deletions command_test.go
Expand Up @@ -461,11 +461,20 @@ func TestCommand_VisibleFlagCategories(t *testing.T) {
&StringFlag{
Name: "strd", // no category set
},
&StringFlag{
Name: "strd1", // no category set and also hidden
Hidden: true,
},
&Int64Flag{
Name: "intd",
Aliases: []string{"altd1", "altd2"},
Category: "cat1",
},
&StringFlag{
Name: "sfd",
Category: "cat2",
Hidden: true,
},
},
}

Expand Down

0 comments on commit 8728c19

Please sign in to comment.