]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix 'go vet -h' to print the right text
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 15 Aug 2018 11:40:07 +0000 (12:40 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 21 Aug 2018 07:36:54 +0000 (07:36 +0000)
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: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/main.go
src/cmd/go/testdata/script/help.txt

index f64ffeb6708f9d61a9ff551a1473f97dd02fa5b7..31c554e715530de632107abf78388c7ed35ec403 100644 (file)
@@ -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)
 }
index cbbd15404b53683fb3d402a3ae6b91518e01ff3b..939da30283ad2ba31351b24fbd1d6c09ab49ca9d 100644 (file)
@@ -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'