* fix: Nil pointer when getting context's flagSet in UsageError function(#1325) * test: add unit test for nil flagset in Context
This commit is contained in:
parent
c2cf7ed6df
commit
e855c4cd1d
@ -151,6 +151,9 @@ func (ctx *Context) lookupFlag(name string) Flag {
|
||||
|
||||
func (ctx *Context) lookupFlagSet(name string) *flag.FlagSet {
|
||||
for _, c := range ctx.Lineage() {
|
||||
if c.flagSet == nil {
|
||||
continue
|
||||
}
|
||||
if f := c.flagSet.Lookup(name); f != nil {
|
||||
return c.flagSet
|
||||
}
|
||||
|
@ -112,6 +112,8 @@ func TestContext_String(t *testing.T) {
|
||||
c := NewContext(nil, set, parentCtx)
|
||||
expect(t, c.String("myflag"), "hello world")
|
||||
expect(t, c.String("top-flag"), "hai veld")
|
||||
c = NewContext(nil, nil, parentCtx)
|
||||
expect(t, c.String("top-flag"), "hai veld")
|
||||
}
|
||||
|
||||
func TestContext_Path(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user