MCPcopy
hub / github.com/urfave/cli / TestCommand_VisibleFlagCategories

Function TestCommand_VisibleFlagCategories

command_test.go:686–736  ·  command_test.go::TestCommand_VisibleFlagCategories
(t *testing.T)

Source from the content-addressed store, hash-verified

684}
685
686func TestCommand_VisibleFlagCategories(t *testing.T) {
687 cmd := &Command{
688 Name: "bar",
689 Usage: "this is for testing",
690 Flags: []Flag{
691 &StringFlag{
692 Name: "strd", // no category set
693 },
694 &StringFlag{
695 Name: "strd1", // no category set and also hidden
696 Hidden: true,
697 },
698 &Int64Flag{
699 Name: "intd",
700 Aliases: []string{"altd1", "altd2"},
701 Category: "cat1",
702 },
703 &StringFlag{
704 Name: "sfd",
705 Category: "cat2", // category set and hidden
706 Hidden: true,
707 },
708 },
709 MutuallyExclusiveFlags: []MutuallyExclusiveFlags{{
710 Category: "cat2",
711 Flags: [][]Flag{
712 {
713 &StringFlag{
714 Name: "mutex",
715 },
716 },
717 },
718 }},
719 }
720
721 cmd.MutuallyExclusiveFlags[0].propagateCategory()
722
723 vfc := cmd.VisibleFlagCategories()
724 require.Len(t, vfc, 3)
725
726 assert.Equal(t, vfc[0].Name(), "", "expected category name to be empty")
727 assert.Equal(t, vfc[0].Flags()[0].Names(), []string{"strd"})
728
729 assert.Equal(t, vfc[1].Name(), "cat1", "expected category name cat1")
730 require.Len(t, vfc[1].Flags(), 1, "expected flag category to have one flag")
731 assert.Equal(t, vfc[1].Flags()[0].Names(), []string{"intd", "altd1", "altd2"})
732
733 assert.Equal(t, vfc[2].Name(), "cat2", "expected category name cat2")
734 require.Len(t, vfc[2].Flags(), 1, "expected flag category to have one flag")
735 assert.Equal(t, vfc[2].Flags()[0].Names(), []string{"mutex"})
736}
737
738func TestCommand_RunSubcommandWithDefault(t *testing.T) {
739 cmd := &Command{

Callers

nothing calls this directly

Calls 6

VisibleFlagCategoriesMethod · 0.95
propagateCategoryMethod · 0.80
LenMethod · 0.65
NameMethod · 0.65
NamesMethod · 0.65
FlagsMethod · 0.65

Tested by

no test coverage detected