-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmd/go: allow go run to pass custom environment variables #63250
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
Comments
go run
CLI to allow to pass environment variables when executing the program
I would argue against complicating |
In a development team some developers might work on Windows while others on Unixes. This is even more true on open source projects where you can't enforce a unified development environment.
|
If the motivation for this is primarily about For example, I imagine that the code that finds With that said, if the environment variable values are going to be hardcoded into a comment in your source code anyway, I would expect that you could equivalently run a small wrapper program included in your own repository which sets those variables and then runs the main tool you intended to run. It would be less convenient of course, but it seems justified for more esoteric needs to have less convenient solutions. I suppose we will see in this discussion whether this is an esoteric need or a common situation! (I personally have not encountered this problem despite making quite extensive use of |
For (But at that point why not have the command accept flags instead?) |
I have written github.com/dolmen-go/env (a portable implementation of |
@bcmills wrote:
Here is one to fix in //go:generate env ZONEINFO=$GOROOT/lib/time/zoneinfo.zip go run genzabbrs.go -output zoneinfo_abbrs_windows.go Replacing the environment variable with a command line flag in |
It seems that #37846 is the perfect use case for this proposal. |
IMHO the problem goes much deeper and the proposal is just a workaround for a different problem: |
Isn't it? Seems like it would just need something like |
This is a proposal to extend the syntax of the command line of
go run
to allow to pass environment variables to the program that is executed after its compilation.The current syntax:
The proposed syntax:
That extended syntax will be incompatible with
=
being used in the package (package name,.go
file) specification. However the language reference already mentions that a compiler implementation may exclude=
from import paths.Why?
go run
which might be needed for building the program (example: x/text/cmd/gotext: generate for one GOOS/GOARCH from a different GOOS/GOARCH #37846)go run
is often used in//go:generate
commands. It is often needed to pass environment variables to the program, but there is no built-in portable way for calling a command with environment variables (env(1)
is available on Unixes, but not on Windows. Workaround: github.com/dolmen-go/env)The text was updated successfully, but these errors were encountered: