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.Commandinitialization 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.