1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package vet implements the ``go vet'' command.
10 "cmd/go/internal/load"
11 "cmd/go/internal/work"
15 var CmdVet
= &base
.Command
{
18 UsageLine
: "vet [-n] [-x] [build flags] [vet flags] [packages]",
19 Short
: "report likely mistakes in packages",
21 Vet runs the Go vet command on the packages named by the import paths.
23 For more about vet and its flags, see 'go doc cmd/vet'.
24 For more about specifying packages, see 'go help packages'.
26 The -n flag prints commands that would be executed.
27 The -x flag prints commands as they are executed.
29 The build flags supported by go vet are those that control package resolution
30 and execution, such as -n, -x, -v, -tags, and -toolexec.
31 For more about these flags, see 'go help build'.
33 See also: go fmt, go fix.
37 func runVet(cmd
*base
.Command
, args
[]string) {
38 vetFlags
, pkgArgs
:= vetFlags(args
)
41 work
.VetFlags
= vetFlags
44 work
.VetTool
, err
= filepath
.Abs(vetTool
)
46 base
.Fatalf("%v", err
)
50 pkgs
:= load
.PackagesForBuild(pkgArgs
)
52 base
.Fatalf("no packages to vet")
58 root
:= &work
.Action
{Mode
: "go vet"}
59 for _
, p
:= range pkgs
{
60 ptest
, pxtest
, err
:= load
.GetTestPackagesFor(p
, false)
62 base
.Errorf("%v", err
)
65 if len(ptest
.GoFiles
) == 0 && len(ptest
.CgoFiles
) == 0 && pxtest
== nil {
66 base
.Errorf("go vet %s: no Go files in %s", p
.ImportPath
, p
.Dir
)
69 if len(ptest
.GoFiles
) > 0 ||
len(ptest
.CgoFiles
) > 0 {
70 root
.Deps
= append(root
.Deps
, b
.VetAction(work
.ModeBuild
, work
.ModeBuild
, ptest
))
73 root
.Deps
= append(root
.Deps
, b
.VetAction(work
.ModeBuild
, work
.ModeBuild
, pxtest
))