Adjust expectations around categorized flags

This commit is contained in:
Dan Buch 2022-11-08 08:17:56 -05:00
parent 75f2d1a83a
commit d294a88a47
Signed by: meatballhat
GPG Key ID: A12F782281063434
3 changed files with 31 additions and 25 deletions

View File

@ -377,12 +377,14 @@ func (c *Command) VisibleCommands() []*Command {
func (c *Command) VisibleFlagCategories() []VisibleFlagCategory {
if c.flagCategories == nil {
c.flagCategories = newFlagCategories()
}
for _, fl := range c.Flags {
if cf, ok := fl.(CategorizableFlag); ok {
c.flagCategories.AddFlag(cf.GetCategory(), fl)
}
}
}
return c.flagCategories.VisibleCategories()
}

View File

@ -470,17 +470,21 @@ func TestCommand_VisibleFlagCategories(t *testing.T) {
}
vfc := c.VisibleFlagCategories()
if len(vfc) != 1 {
t.Fatalf("unexpected visible flag categories %+v", vfc)
}
if vfc[0].Name() != "cat1" {
t.Errorf("expected category name cat1 got %s", vfc[0].Name())
}
if len(vfc[0].Flags()) != 1 {
t.Fatalf("expected flag category to have just one flag got %+v", vfc[0].Flags())
if len(vfc) < 2 {
t.Fatalf("unexpected visible flag categories %+#v", vfc)
}
fl := vfc[0].Flags()[0]
intdCatFlag := vfc[1]
if intdCatFlag.Name() != "cat1" {
t.Errorf("expected category name cat1 got %q", intdCatFlag.Name())
}
if len(intdCatFlag.Flags()) != 1 {
t.Fatalf("expected flag category to have just one flag got %+v", intdCatFlag.Flags())
}
fl := intdCatFlag.Flags()[0]
if !reflect.DeepEqual(fl.Names(), []string{"intd", "altd1", "altd2"}) {
t.Errorf("unexpected flag %+v", fl.Names())
}