(t *testing.T)
| 684 | } |
| 685 | |
| 686 | func 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 | |
| 738 | func TestCommand_RunSubcommandWithDefault(t *testing.T) { |
| 739 | cmd := &Command{ |
nothing calls this directly
no test coverage detected