urfave / cli

A simple, fast, and fun package for building command line apps in Go
https://cli.urfave.org
MIT License
21.9k stars 1.69k forks source link

Missing arg can cause a panic #1864

Closed joshfrench closed 4 months ago

joshfrench commented 4 months ago

What type of PR is this?

What this PR does / why we need it:

--- FAIL: TestSingleOptionalArg (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
        panic: runtime error: index out of range [0] with length 0

goroutine 15 [running]:
testing.tRunner.func1.2({0x163bc20, 0xc00001c660})
        /usr/local/Cellar/go/1.21.4/libexec/src/testing/testing.go:1545 +0x366
testing.tRunner.func1()
        /usr/local/Cellar/go/1.21.4/libexec/src/testing/testing.go:1548 +0x630
panic({0x163bc20?, 0xc00001c660?})
        /usr/local/Cellar/go/1.21.4/libexec/src/runtime/panic.go:920 +0x270
github.com/urfave/cli/v3.(*ArgumentBase[...]).Parse(0x1729d40, {0xc0003381a0, 0x0?, 0x0})
        /Users/josh/src/cli/args.go:136 +0xc88

Testing

Tests added for an omitted arg with max: 1, with and without a default Value.

Release Notes

Optional arguments with arity 1 no longer panic when omitted.