github.com/corona10/go@v0.0.0-20180224231303-7a218942be57/src/cmd/go/internal/fix/fix.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 fix implements the ``go fix'' command.
     6  package fix
     7  
     8  import (
     9  	"cmd/go/internal/base"
    10  	"cmd/go/internal/cfg"
    11  	"cmd/go/internal/load"
    12  	"cmd/go/internal/str"
    13  )
    14  
    15  var CmdFix = &base.Command{
    16  	Run:       runFix,
    17  	UsageLine: "fix [packages]",
    18  	Short:     "update packages to use new APIs",
    19  	Long: `
    20  Fix runs the Go fix command on the packages named by the import paths.
    21  
    22  For more about fix, see 'go doc cmd/fix'.
    23  For more about specifying packages, see 'go help packages'.
    24  
    25  To run fix with specific options, run 'go tool fix'.
    26  
    27  See also: go fmt, go vet.
    28  	`,
    29  }
    30  
    31  func runFix(cmd *base.Command, args []string) {
    32  	for _, pkg := range load.Packages(args) {
    33  		// Use pkg.gofiles instead of pkg.Dir so that
    34  		// the command only applies to this package,
    35  		// not to packages in subdirectories.
    36  		files := base.RelPaths(pkg.InternalAllGoFiles())
    37  		base.Run(str.StringList(cfg.BuildToolexec, base.Tool("fix"), files))
    38  	}
    39  }