github.com/sanprasirt/go@v0.0.0-20170607001320-a027466e4b6d/src/cmd/go/internal/vet/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 vet implements the ``go vet'' command. 6 package vet 7 8 import ( 9 "path/filepath" 10 11 "cmd/go/internal/base" 12 "cmd/go/internal/cfg" 13 "cmd/go/internal/load" 14 "cmd/go/internal/str" 15 ) 16 17 var CmdVet = &base.Command{ 18 Run: runVet, 19 CustomFlags: true, 20 UsageLine: "vet [-n] [-x] [build flags] [vet flags] [packages]", 21 Short: "run go tool vet on packages", 22 Long: ` 23 Vet runs the Go vet command on the packages named by the import paths. 24 25 For more about vet and its flags, see 'go doc cmd/vet'. 26 For more about specifying packages, see 'go help packages'. 27 28 The -n flag prints commands that would be executed. 29 The -x flag prints commands as they are executed. 30 31 For more about build flags, see 'go help build'. 32 33 See also: go fmt, go fix. 34 `, 35 } 36 37 func runVet(cmd *base.Command, args []string) { 38 vetFlags, packages := vetFlags(args) 39 for _, p := range load.Packages(packages) { 40 // Vet expects to be given a set of files all from the same package. 41 // Run once for package p and once for package p_test. 42 if len(p.GoFiles)+len(p.CgoFiles)+len(p.TestGoFiles) > 0 { 43 runVetFiles(p, vetFlags, str.StringList(p.GoFiles, p.CgoFiles, p.TestGoFiles, p.SFiles)) 44 } 45 if len(p.XTestGoFiles) > 0 { 46 runVetFiles(p, vetFlags, str.StringList(p.XTestGoFiles)) 47 } 48 } 49 } 50 51 func runVetFiles(p *load.Package, flags, files []string) { 52 for i := range files { 53 files[i] = filepath.Join(p.Dir, files[i]) 54 } 55 base.Run(cfg.BuildToolexec, base.Tool("vet"), flags, base.RelPaths(files)) 56 }