From 7d74b970200da22d806dfb3ccf478688d833f291 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Sat, 17 Feb 2024 09:39:45 -0500 Subject: [PATCH 1/2] Fix:(issue_1860) Remove hidden flags from flag categories --- category.go | 4 ++-- command_test.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/category.go b/category.go index b1847eca18..0986fffca7 100644 --- a/category.go +++ b/category.go @@ -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 } @@ -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) } } diff --git a/command_test.go b/command_test.go index b3bcf8c562..982d84a45e 100644 --- a/command_test.go +++ b/command_test.go @@ -466,6 +466,11 @@ func TestCommand_VisibleFlagCategories(t *testing.T) { Aliases: []string{"altd1", "altd2"}, Category: "cat1", }, + &StringFlag{ + Name: "sfd", + Category: "cat2", + Hidden: true, + }, }, } From 7b1f820a933644e286f941af47bf5971a5053f9f Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Sat, 17 Feb 2024 20:01:23 -0500 Subject: [PATCH 2/2] Add more tests --- command_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/command_test.go b/command_test.go index 982d84a45e..3f89208a19 100644 --- a/command_test.go +++ b/command_test.go @@ -461,6 +461,10 @@ 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"},