Closed mcmikemn closed 3 months ago
This is how docker itself works. DOCKER_CONTEXT env var will supercede the selected context (which is what tmp-context does). But extra documentation would be good.
I realized that after you explained how tmp-context
worked. But could we do something like this?
d context
and selects new contextWe can spit out a Warning:
DOCKER_CONTEXT=blah - changing your context will have no effect right now
But we can't set a new DOCKER_CONTEXT unless we enter another sub-shell (so now you're in a sub-sub-shell), which I think would be too confusing.
So if we only can issue a warning, should we still allow the context to be changed, or should the warning be upgraded to an error and it quits without doing anything?
If we allow users to change the context while in a tmp-context subshell, the context of the original shell will get updated. I think that is confusing and almost certainly not what the user wants to do.
I think we should prevent users from changing the context while in a tmp-context subshell. The message could be something like:
DOCKER_CONTEXT=blah - To change the context in a subshell, exit the subshell (`ctrl-D`) and create a new subshell (`d tmp-context`).
Hopefully this message captures everything:
$ d context
DOCKER_CONTEXT=wg-sentry-1
The Docker context cannot be switched because the DOCKER_CONTEXT env var is currently set, and this would override your selection.
You may use `d tmp-context` instead, or try exiting the shell you are in, or unset DOCKER_CONTEXT, and try again.
Exiting.
Implemented in 125ced8 as part of #237
That sounds good.
I'm guessing there's nothing wrong with the code, but I just experienced this and so perhaps there shuld be something in the README alerting to the possibility.
I was in context "maincontext" in one shell and I did
d tmp-context
in another shell to open context "subcontext01" at the same time. Then in "subcontext01" I didd context
and switched to "subcontext02", but the shell I was in remained in "subshell01', and the original shell switched from being in "maincontext" to "subcontext02".