From d7ab57efda161c1757e591ec469ca4d01976cb66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Wed, 15 Aug 2018 12:40:07 +0100 Subject: [PATCH] cmd/go: fix 'go vet -h' to print the right text MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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í TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike Reviewed-by: Russ Cox --- src/cmd/go/main.go | 7 +++++++ src/cmd/go/testdata/script/help.txt | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index f64ffeb670..31c554e715 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -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) } diff --git a/src/cmd/go/testdata/script/help.txt b/src/cmd/go/testdata/script/help.txt index cbbd15404b..939da30283 100644 --- a/src/cmd/go/testdata/script/help.txt +++ b/src/cmd/go/testdata/script/help.txt @@ -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' -- 2.50.0