-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add support for context.Context #893
Conversation
This does seem like a decent solution for shoe-horning context support into cobra.Command. |
I rebased this PR against origin, so that now the build passes (seems like there were some issues upstream previously). So, hope this can be merged soon. |
Fixed merge conflicts again. |
Can this be merged? |
The lack of support of PS @burdiyan thanks a lot for the work! |
@cpuguy83 could you approve and merge this is PR? |
I am not a maintainer on this project. |
Bump? |
@hairyhenderson, see #959. |
thank you! I think something in the root README would be helpful here |
Is it possible to update the context in one command Run/PersistentPreRun so that the altered context is what's passed down to the subcommands? |
@aventurella-honey I believe it's not possible. Because context is immutable and you'll have to store altered context somewhere to pass it on to the subcommands, and currently the only way to pass the context is to call ExecuteContext. |
This PR adds support for
context.Context
. It could help people struggling with passing context to the Run functions, that previously had to wrapcobra.Command
initialization inside another function that would accept context.So now instead of doing:
you would do:
This PR is fully backward-compatible, and doesn't require users to use context at all.
It renders this PR #727 (which seems to have conficlits, and also goes against the idiomatic way of using context) irrelevant.