github.com/bgentry/go@v0.0.0-20150121062915-6cf5a733d54d/src/cmd/go/vet.go (about) 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. 4 5 package main 6 7 import "path/filepath" 8 9 func init() { 10 addBuildFlagsNX(cmdVet) 11 } 12 13 var cmdVet = &Command{ 14 Run: runVet, 15 UsageLine: "vet [-n] [-x] [packages]", 16 Short: "run go tool vet on packages", 17 Long: ` 18 Vet runs the Go vet command on the packages named by the import paths. 19 20 For more about vet, see 'godoc golang.org/x/tools/cmd/vet'. 21 For more about specifying packages, see 'go help packages'. 22 23 To run the vet tool with specific options, run 'go tool vet'. 24 25 The -n flag prints commands that would be executed. 26 The -x flag prints commands as they are executed. 27 28 See also: go fmt, go fix. 29 `, 30 } 31 32 func runVet(cmd *Command, args []string) { 33 for _, p := range packages(args) { 34 // Vet expects to be given a set of files all from the same package. 35 // Run once for package p and once for package p_test. 36 if len(p.GoFiles)+len(p.CgoFiles)+len(p.TestGoFiles) > 0 { 37 runVetFiles(p, stringList(p.GoFiles, p.CgoFiles, p.TestGoFiles, p.SFiles)) 38 } 39 if len(p.XTestGoFiles) > 0 { 40 runVetFiles(p, stringList(p.XTestGoFiles)) 41 } 42 } 43 } 44 45 func runVetFiles(p *Package, files []string) { 46 for i := range files { 47 files[i] = filepath.Join(p.Dir, files[i]) 48 } 49 run(tool("vet"), relPaths(files)) 50 }