github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/not-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  	"github.com/gagliardetto/golang-go/cmd/go/not-internal/base"
    10  	"github.com/gagliardetto/golang-go/cmd/go/not-internal/cfg"
    11  	"github.com/gagliardetto/golang-go/cmd/go/not-internal/load"
    12  	"github.com/gagliardetto/golang-go/cmd/go/not-internal/modload"
    13  	"github.com/gagliardetto/golang-go/cmd/go/not-internal/str"
    14  	"fmt"
    15  	"os"
    16  )
    17  
    18  var CmdFix = &base.Command{
    19  	Run:       runFix,
    20  	UsageLine: "go fix [packages]",
    21  	Short:     "update packages to use new APIs",
    22  	Long: `
    23  Fix runs the Go fix command on the packages named by the import paths.
    24  
    25  For more about fix, see 'go doc cmd/fix'.
    26  For more about specifying packages, see 'go help packages'.
    27  
    28  To run fix with specific options, run 'go tool fix'.
    29  
    30  See also: go fmt, go vet.
    31  	`,
    32  }
    33  
    34  func runFix(cmd *base.Command, args []string) {
    35  	printed := false
    36  	for _, pkg := range load.Packages(args) {
    37  		if modload.Enabled() && pkg.Module != nil && !pkg.Module.Main {
    38  			if !printed {
    39  				fmt.Fprintf(os.Stderr, "go: not fixing packages in dependency modules\n")
    40  				printed = true
    41  			}
    42  			continue
    43  		}
    44  		// Use pkg.gofiles instead of pkg.Dir so that
    45  		// the command only applies to this package,
    46  		// not to packages in subdirectories.
    47  		files := base.RelPaths(pkg.InternalAllGoFiles())
    48  		base.Run(str.StringList(cfg.BuildToolexec, base.Tool("fix"), files))
    49  	}
    50  }