Commit d7ab57ef authored by Daniel Martí's avatar Daniel Martí

cmd/go: fix 'go vet -h' to print the right text

For the last two releases, its output has been the same as 'go -h'.

The test and vet sub-commands share their flag logic via the cmdflag
package, so fixing it there would mean a larger refactor. Moreover, the
test subcommand handles its '-h' flag in a special way; that's #26999.

For now, use a much less invasive fix, mirroring the special-casing of
'test -h' to simply print vet's short usage text.

Also add a regression test via a cmd/go test script.

Fixes #26998.

Change-Id: Ie6b866d98116a1bc5f84a204e1c9f1c2f6b48bff
Reviewed-on: https://go-review.googlesource.com/129318
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRob Pike <r@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 187a41db
......@@ -239,6 +239,13 @@ func mainUsage() {
if len(os.Args) > 1 && os.Args[1] == "test" {
test.Usage()
}
// Since vet shares code with test in cmdflag, it doesn't show its
// command usage properly. For now, special case it too.
// TODO(mvdan): fix the cmdflag package instead; see
// golang.org/issue/26999
if len(os.Args) > 1 && os.Args[1] == "vet" {
vet.CmdVet.Usage()
}
help.PrintUsage(os.Stderr, base.Go)
os.Exit(2)
}
......@@ -28,3 +28,9 @@ stdout 'usage: go mod tidy'
# go mod --help doesn't print help but at least suggests it.
! go mod --help
stderr 'Run ''go help mod'' for usage.'
# Earlier versions of Go printed the same as 'go -h' here.
# Also make sure we print the short help line.
! go vet -h
stderr 'usage: go vet'
stderr 'Run ''go help vet'' for details'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment