Fix: (issue#1254) short options handling needs to proceed from last terminated error
This commit is contained in:
parent
850cf82509
commit
156d47e696
31
flag_test.go
31
flag_test.go
@ -2059,3 +2059,34 @@ func TestTimestampFlagApply_WithDestination(t *testing.T) {
|
||||
expect(t, err, nil)
|
||||
expect(t, *fl.Destination.timestamp, expectedResult)
|
||||
}
|
||||
|
||||
// Test issue #1254
|
||||
// StringSlice() with UseShortOptionHandling causes duplicated entries, depending on the ordering of the flags
|
||||
func TestSliceShortOptionHandle(t *testing.T) {
|
||||
_ = (&App{
|
||||
Commands: []*Command{
|
||||
{
|
||||
Name: "foobar",
|
||||
UseShortOptionHandling: true,
|
||||
Action: func(ctx *Context) error {
|
||||
if ctx.Bool("i") != true {
|
||||
t.Errorf("bool i not set")
|
||||
}
|
||||
if ctx.Bool("t") != true {
|
||||
t.Errorf("bool i not set")
|
||||
}
|
||||
ss := ctx.StringSlice("net")
|
||||
if !reflect.DeepEqual(ss, []string{"foo"}) {
|
||||
t.Errorf("Got different slice(%v) than expected", ss)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Flags: []Flag{
|
||||
&StringSliceFlag{Name: "net"},
|
||||
&BoolFlag{Name: "i"},
|
||||
&BoolFlag{Name: "t"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).Run([]string{"run", "foobar", "--net=foo", "-it"})
|
||||
}
|
||||
|
5
parse.go
5
parse.go
@ -46,8 +46,9 @@ func parseIter(set *flag.FlagSet, ip iterativeParser, args []string, shellComple
|
||||
return err
|
||||
}
|
||||
|
||||
// swap current argument with the split version
|
||||
args = append(args[:i], append(shortOpts, args[i+1:]...)...)
|
||||
// Start processing only from failed argument and not
|
||||
// from beginning
|
||||
args = append(shortOpts, args[i+1:]...)
|
||||
argsWereSplit = true
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user