Adjust expectations around categorized flags
This commit is contained in:
parent
75f2d1a83a
commit
d294a88a47
10
command.go
10
command.go
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
for _, fl := range c.Flags {
|
||||
if cf, ok := fl.(CategorizableFlag); ok {
|
||||
c.flagCategories.AddFlag(cf.GetCategory(), fl)
|
||||
}
|
||||
}
|
||||
|
||||
return c.flagCategories.VisibleCategories()
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -5,24 +5,24 @@ line Go applications. cli is designed to be easy to understand and write,
|
||||
the most simple cli application can be written as follows:
|
||||
|
||||
func main() {
|
||||
(&cli.App{}).Run(os.Args)
|
||||
(&cli.App{}).Run(os.Args)
|
||||
}
|
||||
|
||||
Of course this application does not do much, so let's make this an actual
|
||||
application:
|
||||
|
||||
func main() {
|
||||
app := &cli.App{
|
||||
Name: "greet",
|
||||
Usage: "say a greeting",
|
||||
Action: func(c *cli.Context) error {
|
||||
fmt.Println("Greetings")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
func main() {
|
||||
app := &cli.App{
|
||||
Name: "greet",
|
||||
Usage: "say a greeting",
|
||||
Action: func(c *cli.Context) error {
|
||||
fmt.Println("Greetings")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
app.Run(os.Args)
|
||||
}
|
||||
app.Run(os.Args)
|
||||
}
|
||||
|
||||
VARIABLES
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user