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.
11 "cmd/go/internal/load"
12 "cmd/go/internal/modload"
18 var CmdFix
= &base
.Command
{
20 UsageLine
: "go fix [packages]",
21 Short
: "update packages to use new APIs",
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) {
36 for _
, pkg
:= range load
.Packages(args
) {
37 if modload
.Enabled() && !pkg
.Module
.Main
{
39 fmt
.Fprintf(os
.Stderr
, "go: not fixing packages in dependency modules\n")
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
))