Prevent panic on flagSet access from custom BashComplete

Fixes #944
This commit is contained in:
Roberto Hidalgo
2019-11-25 14:25:11 -05:00
parent 4805bd168c
commit 90a62d7b0c
2 changed files with 51 additions and 3 deletions

View File

@@ -100,7 +100,7 @@ func (c *Command) Run(ctx *Context) (err error) {
c.UseShortOptionHandling = true
}
set, err := c.parseFlags(ctx.Args())
set, err := c.parseFlags(ctx.Args(), ctx.shellComplete)
context := NewContext(ctx.App, set, ctx)
context.Command = c
@@ -174,7 +174,7 @@ func (c *Command) useShortOptionHandling() bool {
return c.UseShortOptionHandling
}
func (c *Command) parseFlags(args Args) (*flag.FlagSet, error) {
func (c *Command) parseFlags(args Args, shellComplete bool) (*flag.FlagSet, error) {
set, err := c.newFlagSet()
if err != nil {
return nil, err
@@ -185,7 +185,8 @@ func (c *Command) parseFlags(args Args) (*flag.FlagSet, error) {
}
err = parseIter(set, c, args.Tail())
if err != nil {
// Continue parsing flags on failure during shell completion
if err != nil && !shellComplete {
return nil, err
}