]> Cypherpunks repositories - gostls13.git/commit
cmd/go: relax version's error on unexpected flags
authorDaniel Martí <mvdan@mvdan.cc>
Thu, 10 Sep 2020 21:53:59 +0000 (22:53 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 15 Sep 2020 15:30:56 +0000 (15:30 +0000)
commitde0957dc081e1ec49c99a0f37403ceadbaaedf85
treef6319bcff2455bb4d5bf29e38a084609427c11e3
parentf1c400a06393aad55cd4758fc78ccd7aec379ec0
cmd/go: relax version's error on unexpected flags

In https://golang.org/cl/221397 we made commands like "go version -v"
error, since both of the command's flags only make sense when arguments
follow them. Without arguments, the command only reports Go's own
version, and the flags are most likely a mistake.

However, the script below is entirely reasonable:

export GOFLAGS=-v # make all Go commands verbose
go version
go build

After the previous CL, "go version" would error. Instead, only error if
the flag was passed explicitly, and not via GOFLAGS.

The patch does mean that we won't error on "GOFLAGS=-v go version -v",
but that very unlikely false negative is okay. The error is only meant
to help the user not misuse the flags, anyway - it's not a critical
error of any sort.

To reuse inGOFLAGS, we move it to the base package and export it there,
since it's where the rest of the GOFLAGS funcs are.

Fixes #41264.

Change-Id: I74003dd25d94bacf9ac507b5cad778fd65233321
Reviewed-on: https://go-review.googlesource.com/c/go/+/254157
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/base/goflags.go
src/cmd/go/internal/version/version.go
src/cmd/go/internal/work/init.go
src/cmd/go/testdata/script/version.txt