github.com/goproxy0/go@v0.0.0-20171111080102-49cc0c489d2c/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 "cmd/go/internal/base" 10 "cmd/go/internal/load" 11 "cmd/go/internal/work" 12 ) 13 14 var CmdVet = &base.Command{ 15 Run: runVet, 16 CustomFlags: true, 17 UsageLine: "vet [-n] [-x] [build flags] [vet flags] [packages]", 18 Short: "report likely mistakes in packages", 19 Long: ` 20 Vet runs the Go vet command on the packages named by the import paths. 21 22 For more about vet and its flags, see 'go doc cmd/vet'. 23 For more about specifying packages, see 'go help packages'. 24 25 The -n flag prints commands that would be executed. 26 The -x flag prints commands as they are executed. 27 28 The build flags supported by go vet are those that control package resolution 29 and execution, such as -n, -x, -v, -tags, and -toolexec. 30 For more about these flags, see 'go help build'. 31 32 See also: go fmt, go fix. 33 `, 34 } 35 36 func runVet(cmd *base.Command, args []string) { 37 vetFlags, pkgArgs := vetFlags(args) 38 39 work.BuildInit() 40 work.VetFlags = vetFlags 41 42 pkgs := load.PackagesForBuild(pkgArgs) 43 if len(pkgs) == 0 { 44 base.Fatalf("no packages to vet") 45 } 46 47 var b work.Builder 48 b.Init() 49 50 root := &work.Action{Mode: "go vet"} 51 for _, p := range pkgs { 52 root.Deps = append(root.Deps, b.VetAction(work.ModeBuild, work.ModeBuild, p)) 53 } 54 b.Do(root) 55 }