mirror of
https://github.com/spf13/cobra
synced 2025-05-05 12:57:22 +00:00
Command.Context() returns nil instead of context.Background()
This commit is contained in:
parent
e04ec72550
commit
f5f90a22c6
2 changed files with 10 additions and 0 deletions
|
@ -227,6 +227,9 @@ type Command struct {
|
||||||
// Context returns underlying command context. If command wasn't
|
// Context returns underlying command context. If command wasn't
|
||||||
// executed with ExecuteContext Context returns Background context.
|
// executed with ExecuteContext Context returns Background context.
|
||||||
func (c *Command) Context() context.Context {
|
func (c *Command) Context() context.Context {
|
||||||
|
if c.ctx == nil {
|
||||||
|
c.ctx = context.Background()
|
||||||
|
}
|
||||||
return c.ctx
|
return c.ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2058,3 +2058,10 @@ func TestFParseErrWhitelistSiblingCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
checkStringContains(t, output, "unknown flag: --unknown")
|
checkStringContains(t, output, "unknown flag: --unknown")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext(t *testing.T) {
|
||||||
|
root := &Command{}
|
||||||
|
if root.Context() == nil {
|
||||||
|
t.Error("expected root.Context() != nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue