...
Source file src/cmd/go/internal/fix/fix.go
1
2
3
4
5
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/modload"
13 "cmd/go/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
45
46
47 files := base.RelPaths(pkg.InternalAllGoFiles())
48 base.Run(str.StringList(cfg.BuildToolexec, base.Tool("fix"), files))
49 }
50 }
51
View as plain text