-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Child command context is not updated when global context changed #2077
Comments
Thanks @libozh Lines 1109 to 1113 in 199b7ab
In the above code I haven't used contexts with Cobra, but my guess is that you can set a different context for a sub-command than for the root and therefore you don't want the root context to overwrite the sub-command context. So it seems reasonable to me. Was your observation based on looking at the code or did you hit a problem with this logic?
I'm not sure when a context could change. I think it is set once for one program execution. |
Thank you Marc for the feedback. |
In command.go
func (c *Command) ExecuteC() (cmd *Command, err error) {
...
// We have to pass global context to children command
// if context is present on the parent command.
if cmd.ctx == nil {
cmd.ctx = c.ctx
}
...
}
The code doesn't match the intention of the comment. c.ctx hold the global context. Should the code be:
Without this change, if global context changed, the child command still hold the old context.
The text was updated successfully, but these errors were encountered: