-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent panic on flagSet access from custom BashComplete #946
Changes from 1 commit
90a62d7
f3295e3
9e7226e
d733c54
233958c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This basically allows for the context to continue to be parsed. Malformed flags will still be ignored and not part of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OH! Actually! I have a better idea: can you change this code to pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea!
|
||
return nil, err | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure if this name/concept is right as an argument, kept it for the sake of consistency but happy to adjust if someone has a better idea!