From d58c46a0d611f417db97c4a568303e2f61f46579 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 19 May 2020 17:07:08 -0300 Subject: [PATCH] Add SetContext() function to cobra.Command --- command.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/command.go b/command.go index 5b81f61d..7e55dcfd 100644 --- a/command.go +++ b/command.go @@ -216,6 +216,12 @@ func (c *Command) Context() context.Context { return c.ctx } +// SetContext replaces the underlying command context so that parent +// commands can pass down values to their subcommands. +func (c *Command) SetContext(ctx context.Context) { + c.ctx = ctx +} + // SetArgs sets arguments for the command. It is set to os.Args[1:] by default, if desired, can be overridden // particularly useful when testing. func (c *Command) SetArgs(a []string) {