| 1 | package cliscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ |
| 2 | |
| 3 | import ( |
| 4 | "stringsscip-go gomod github.com/golang/go/src go1.22 strings/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.22 testing/" |
| 6 | |
| 7 | "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/" |
| 8 | ) |
| 9 | |
| 10 | func newCommandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/newCommand().() *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command# { |
| 11 | return &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 12 | MutuallyExclusiveFlagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#MutuallyExclusiveFlags.: []MutuallyExclusiveFlagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MutuallyExclusiveFlags#{ |
| 13 | { |
| 14 | Flagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MutuallyExclusiveFlags#Flags.: [][]Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#{ |
| 15 | { |
| 16 | &Int64Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Int64Flag#{ |
| 17 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Name.: "i", |
| 18 | }, |
| 19 | &StringFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/StringFlag#{ |
| 20 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Name.: "s", |
| 21 | Sourcesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Sources.: EnvVarsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/EnvVars().("S_VAR"), |
| 22 | }, |
| 23 | &BoolWithInverseFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/BoolWithInverseFlag#{ |
| 24 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/BoolWithInverseFlag#Name.: "b", |
| 25 | }, |
| 26 | }, |
| 27 | { |
| 28 | &Int64Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Int64Flag#{ |
| 29 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Name.: "t", |
| 30 | Aliasesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Aliases.: []string{"ai"}, |
| 31 | Sourcesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Sources.: EnvVarsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/EnvVars().("T_VAR"), |
| 32 | }, |
| 33 | }, |
| 34 | }, |
| 35 | }, |
| 36 | }, |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func TestFlagMutuallyExclusiveFlagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestFlagMutuallyExclusiveFlags().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 41 | tests := []struct { |
| 42 | name string |
| 43 | args []string |
| 44 | errStr string |
| 45 | required bool |
| 46 | envs map[string]string |
| 47 | }{ |
| 48 | { |
| 49 | name: "simple", |
| 50 | }, |
| 51 | { |
| 52 | name: "set one flag", |
| 53 | args: []string{"--i", "10"}, |
| 54 | }, |
| 55 | { |
| 56 | name: "set both flags", |
| 57 | args: []string{"--i", "11", "--ai", "12"}, |
| 58 | errStr: "option i cannot be set along with option ai", |
| 59 | }, |
| 60 | { |
| 61 | name: "required none set", |
| 62 | required: true, |
| 63 | errStr: "one of these flags needs to be provided", |
| 64 | }, |
| 65 | { |
| 66 | name: "required one set", |
| 67 | args: []string{"--i", "10"}, |
| 68 | required: true, |
| 69 | }, |
| 70 | { |
| 71 | name: "required both set", |
| 72 | args: []string{"--i", "11", "--ai", "12"}, |
| 73 | errStr: "option i cannot be set along with option ai", |
| 74 | required: true, |
| 75 | }, |
| 76 | { |
| 77 | name: "set env var", |
| 78 | required: true, |
| 79 | envs: map[string]string{ |
| 80 | "S_VAR": "some", |
| 81 | }, |
| 82 | }, |
| 83 | } |
| 84 | |
| 85 | for _, test := range tests { |
| 86 | t.Runscip-go gomod github.com/golang/go/src go1.22 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 87 | if test.envs != nil { |
| 88 | for k, v := range test.envs { |
| 89 | t.Setenvscip-go gomod github.com/golang/go/src go1.22 testing/T#Setenv().(k, v) |
| 90 | } |
| 91 | } |
| 92 | cmd := newCommandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/newCommand().() |
| 93 | cmd.MutuallyExclusiveFlagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#MutuallyExclusiveFlags.[0].Requiredscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/MutuallyExclusiveFlags#Required. = test.required |
| 94 | |
| 95 | err := cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), append([]string{"foo"}, test.args...)) |
| 96 | if test.errStr == "" { |
| 97 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoError().(t, err) |
| 98 | return |
| 99 | } |
| 100 | if err == nil { |
| 101 | t.Errorscip-go gomod github.com/golang/go/src go1.22 testing/common#Error().("Expected mutual exclusion error") |
| 102 | return |
| 103 | } |
| 104 | |
| 105 | switch err.(type) { |
| 106 | case (*mutuallyExclusiveGroupscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/mutuallyExclusiveGroup#), (*mutuallyExclusiveGroupRequiredFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/mutuallyExclusiveGroupRequiredFlag#): |
| 107 | if !stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Containsscip-go gomod github.com/golang/go/src go1.22 strings/Contains().(err.Error(), test.errStr) { |
| 108 | t.Logfscip-go gomod github.com/golang/go/src go1.22 testing/common#Logf().("Invalid error string %v", err) |
| 109 | } |
| 110 | default: |
| 111 | t.Errorfscip-go gomod github.com/golang/go/src go1.22 testing/common#Errorf().("got invalid error type %T", err) |
| 112 | } |
| 113 | }) |
| 114 | } |
| 115 | } |