From 1651eec7b89a7e727630b8b2591d91d7346dc40a Mon Sep 17 00:00:00 2001 From: Lynn Cyrin Date: Tue, 24 Dec 2019 08:53:59 -0800 Subject: [PATCH] add a fix --- context.go | 4 ++++ context_test.go | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index e1cf3da..4d8c023 100644 --- a/context.go +++ b/context.go @@ -33,6 +33,10 @@ func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context { if parentCtx != nil { c.Context = parentCtx.Context c.shellComplete = parentCtx.shellComplete + + if parentCtx.flagSet == nil { + parentCtx.flagSet = &flag.FlagSet{} + } } c.Command = &Command{} diff --git a/context_test.go b/context_test.go index 818cb5a..8f255eb 100644 --- a/context_test.go +++ b/context_test.go @@ -380,8 +380,8 @@ func TestContextAttributeAccessing(t *testing.T) { for _, test := range tdata { t.Run(test.testCase, func(t *testing.T) { // setup - set := flag.NewFlagSet("test", 0) - set.Bool(test.setBoolInput, false, "doc") + set := flag.NewFlagSet("some-flag-set-name", 0) + set.Bool(test.setBoolInput, false, "usage documentation") ctx := NewContext(nil, set, test.newContextInput) // logic under test @@ -389,7 +389,7 @@ func TestContextAttributeAccessing(t *testing.T) { // assertions if value != false { - t.Errorf("expected test.value to be false, but it was not") + t.Errorf("expected \"value\" to be false, but it was not") } }) }