• haya14busa's avatar
    cmd/go: add -json flag to go env · 846f9254
    haya14busa authored
    "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 #12567
    
    Change-Id: I75db3780f14a8ab8c7fa58cc3c9cc488ef7b66a1
    Reviewed-on: https://go-review.googlesource.com/38757Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    846f9254
Name
Last commit
Last update
..
README Loading commit data...
build.go Loading commit data...
buildgo.go Loading commit data...
buildruntime.go Loading commit data...
buildtool.go Loading commit data...
cpuid_386.s Loading commit data...
cpuid_amd64.s Loading commit data...
cpuid_default.s Loading commit data...
deps.go Loading commit data...
main.go Loading commit data...
mkdeps.bash Loading commit data...
sys_default.go Loading commit data...
sys_windows.go Loading commit data...
test.go Loading commit data...
test_linux.go Loading commit data...
util.go Loading commit data...
util_gc.go Loading commit data...
util_gccgo.go Loading commit data...
vfp_arm.s Loading commit data...
vfp_default.s Loading commit data...