8000 Merge remote-tracking branch 'origin/main' into release-metadata · urfave/cli@68da1cd · GitHub
[go: up one dir, main page]

Skip to co 10000 ntent

Commit 68da1cd

Browse files
committed
Merge remote-tracking branch 'origin/main' into release-metadata
2 parents de58951 + c864c24 commit 68da1cd

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

flag_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,3 +2241,42 @@ func TestTimestampFlagApply_WithDestination(t *testing.T) {
22412241
expect(t, err, nil)
22422242
expect(t, *fl.Destination.timestamp, expectedResult)
22432243
}
2244+
2245+
// Test issue #1254
2246+
// StringSlice() with UseShortOptionHandling causes duplicated entries, depending on the ordering of the flags
2247+
func TestSliceShortOptionHandle(t *testing.T) {
2248+
wasCalled := false
2249+
err := (&App{
2250+
Commands: []*Command{
2251+
{
2252+
Name: "foobar",
2253+
UseShortOptionHandling: true,
2254+
Action: func(ctx *Context) error {
2255+
wasCalled = true
2256+
if ctx.Bool("i") != true {
2257+
t.Error("bool i not set")
2258+
}
2259+
if ctx.Bool("t") != true {
2260+
t.Error("bool i not set")
2261+
}
2262+
ss := ctx.StringSlice("net")
2263+
if !reflect.DeepEqual(ss, []string{"foo"}) {
2264+
t.Errorf("Got different slice(%v) than expected", ss)
2265+
}
2266+
return nil
2267+
},
2268+
Flags: []Flag{
2269+
&StringSliceFlag{Name: "net"},
2270+
&BoolFlag{Name: "i"},
2271+
&BoolFlag{Name: "t"},
2272+
},
2273+
},
2274+
},
2275+
}).Run([]string{"run", "foobar", "--net=foo", "-it"})
2276+
if err != nil {
2277+
t.Fatal(err)
2278+
}
2279+
if !wasCalled {
2280+
t.Fatal("Action callback was never called")
2281+
}
2282+
}

0 commit comments

Comments
 (0)
0