Skip to content

Commit 8728c19

Browse files
authored
Merge pull request #1868 from dearchap/issue_1860
Fix:(issue_1860) Remove hidden flags from flag categories
2 parents 09c3974 + 64b40d2 commit 8728c19

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

category.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
104104
var categorized bool
105105
for _, fl := range fs {
106106
if cf, ok := fl.(CategorizableFlag); ok {
107-
if cat := cf.GetCategory(); cat != "" {
107+
if cat := cf.GetCategory(); cat != "" && cf.IsVisible() {
108108
fc.AddFlag(cat, cf)
109109
categorized = true
110110
}
@@ -114,7 +114,7 @@ func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
114114
if categorized {
115115
for _, fl := range fs {
116116
if cf, ok := fl.(CategorizableFlag); ok {
117-
if cf.GetCategory() == "" {
117+
if cf.GetCategory() == "" && cf.IsVisible() {
118118
fc.AddFlag("", fl)
119119
}
120120
}

command_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,20 @@ func TestCommand_VisibleFlagCategories(t *testing.T) {
461461
&StringFlag{
462462
Name: "strd", // no category set
463463
},
464+
&StringFlag{
465+
Name: "strd1", // no category set and also hidden
466+
Hidden: true,
467+
},
464468
&Int64Flag{
465469
Name: "intd",
466470
Aliases: []string{"altd1", "altd2"},
467471
Category: "cat1",
468472
},
473+
&StringFlag{
474+
Name: "sfd",
475+
Category: "cat2",
476+
Hidden: true,
477+
},
469478
},
470479
}
471480

0 commit comments

Comments
 (0)