v2 bug: ctx.NArg() panics on Command.BashComplete #944
Labels
area/v2
relates to / is being considered for v2
kind/bug
describes or fixes a bug
status/claimed
someone has claimed this issue
Checklist
Describe the bug
ctx.flagSet
is nil duringcli.Command.BashComplete
when a malformed flag is passed, either misspelled or with an invalid value, leading to a panic when callingctx.NArg()
. For example:To reproduce
With released
v2.0.0
ongo version go1.12.5 darwin/amd64
the following example results inpanic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x11752c2]
Expected behavior
0
output to stdout. Noticed after upgrade tov2.0.0
fromd3ae77c26ac8
, according to my go.mod.Additional context
I started working my way through parser.go@06e3d38d88, which is where the
nil
value for my command'sflagSet
seems to be last seen, but this is still more of a hunch than a fact. I also feel like there's might be some initialization that I should be doing inside the command'sBashComplete
that I'm missing?Complete panic:
Want to fix this yourself?
Happy to take a stab at if this is a valid use case, and some guidance on an approach to doing so would be much appreciated! Or maybe this is more of a documentation issue, and I should try something like what's done in
DefaultCompleteWithFlags
instead of usingctx.NArg()
? in which case I can send a PR to the manual.Run
go env
and paste its output hereThe text was updated successfully, but these errors were encountered: