github.com/FenixAra/go@v0.0.0-20170127160404-96ea0918e670/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 addBuildFlags(cmdVet) 11 } 12 13 var cmdVet = &Command{ 14 Run: runVet, 15 UsageLine: "vet [-n] [-x] [build flags] [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 'go doc 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 For more about build flags, see 'go help build'. 29 30 See also: go fmt, go fix. 31 `, 32 } 33 34 func runVet(cmd *Command, args []string) { 35 for _, p := range packages(args) { 36 // Vet expects to be given a set of files all from the same package. 37 // Run once for package p and once for package p_test. 38 if len(p.GoFiles)+len(p.CgoFiles)+len(p.TestGoFiles) > 0 { 39 runVetFiles(p, stringList(p.GoFiles, p.CgoFiles, p.TestGoFiles, p.SFiles)) 40 } 41 if len(p.XTestGoFiles) > 0 { 42 runVetFiles(p, stringList(p.XTestGoFiles)) 43 } 44 } 45 } 46 47 func runVetFiles(p *Package, files []string) { 48 for i := range files { 49 files[i] = filepath.Join(p.Dir, files[i]) 50 } 51 run(buildToolExec, tool("vet"), relPaths(files)) 52 }