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
cmd/go: Add -json flag to go env command #12567
Comments
I would also very much like this flag to be available for Would something like this be acceptable as a contribution? If so, I will go ahead and make the necessary changes and submit it. |
What is the variance between platforms, and how would the |
@adg: the variance:
The variance is explained by the fact that The rationale for JSON is that some tools (e.g. editor packages / plugins) aren't interested in shell scripts as output; they're interested in a structured format that does not vary by platform. Unsurprisingly, the output of In some respects, adding a json option will just add code to such tools (if they wish to function correctly with prior versions of go, they'll still need to handle the shell script output variant), but at least it makes future releases easier to work with. |
Seems like a reasonable feature to me. Happy to review the change. |
@joefitzgerald did you want to propose the change to gerrit or shall I? I'm happy to review something if you'd like to. |
@mattfarina It'll be a few days before I can get to this. If you have the time now, please go for it. |
I'm assuming that this feature is still worth considering to implement. sent a CL. |
CL https://golang.org/cl/38757 mentions this issue. |
"go env" prints Go environment information as a shell script format by default but it's difficult for some tools (e.g. editor packages) to interpret it. The -json flag prints the environment in JSON format which can be easily interpreted by a lot of tools. $ go env -json { "CC": "gcc", "CGO_CFLAGS": "-g -O2", "CGO_CPPFLAGS": "", "CGO_CXXFLAGS": "-g -O2", "CGO_ENABLED": "1", "CGO_FFLAGS": "-g -O2", "CGO_LDFLAGS": "-g -O2", "CXX": "g++", "GCCGO": "gccgo", "GOARCH": "amd64", "GOBIN": "/home/haya14busa/go/bin", "GOEXE": "", "GOGCCFLAGS": "-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build498013955=/tmp/go-build -gno-record-gcc-switches", "GOHOSTARCH": "amd64", "GOHOSTOS": "linux", "GOOS": "linux", "GOPATH": "/home/haya14busa", "GORACE": "", "GOROOT": "/home/haya14busa/src/go.googlesource.com/go", "GOTOOLDIR": "/home/haya14busa/src/go.googlesource.com/go/pkg/tool/linux_amd64", "PKG_CONFIG": "pkg-config" } Also, it supports arguments with -json flag. $ go env -json GOROOT GOPATH GOBIN { "GOBIN": "/home/haya14busa/go/bin", "GOPATH": "/home/haya14busa", "GOROOT": "/home/haya14busa/src/go.googlesource.com/go" } Fixes golang#12567 Change-Id: I75db3780f14a8ab8c7fa58cc3c9cc488ef7b66a1 Reviewed-on: https://go-review.googlesource.com/38757 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Getting the go environment is useful for tools built to compliment the local environment. Being able to parse the Go environment easily would be useful. Currently,
go env
provides a listing of the Go environment (including defaults not always available such as$GOPATH
) andgo env [VAR]
provides the value of an individual variable.It would be useful to get the output of
go env
as a json string as well as a listing.The text was updated successfully, but these errors were encountered: