libgo: update to Go 1.11
[official-gcc.git] / libgo / go / cmd / go / internal / fix / fix.go
blobaab164148ff88a62424db7818d0584fb675c2daf
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.
5 // Package fix implements the ``go fix'' command.
6 package fix
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"
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.
25 For more about fix, see 'go doc cmd/fix'.
26 For more about specifying packages, see 'go help packages'.
28 To run fix with specific options, run 'go tool fix'.
30 See also: go fmt, go vet.
34 func runFix(cmd *base.Command, args []string) {
35 printed := false
36 for _, pkg := range load.Packages(args) {
37 if modload.Enabled() && !pkg.Module.Main {
38 if !printed {
39 fmt.Fprintf(os.Stderr, "go: not fixing packages in dependency modules\n")
40 printed = true
42 continue
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))