summaryrefslogtreecommitdiffstats
path: root/src/cmd/go/internal/fix/fix.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:14:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:14:23 +0000
commit73df946d56c74384511a194dd01dbe099584fd1a (patch)
treefd0bcea490dd81327ddfbb31e215439672c9a068 /src/cmd/go/internal/fix/fix.go
parentInitial commit. (diff)
downloadgolang-1.16-upstream.tar.xz
golang-1.16-upstream.zip
Adding upstream version 1.16.10.upstream/1.16.10upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/cmd/go/internal/fix/fix.go')
-rw-r--r--src/cmd/go/internal/fix/fix.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/cmd/go/internal/fix/fix.go b/src/cmd/go/internal/fix/fix.go
new file mode 100644
index 0000000..c7588c6
--- /dev/null
+++ b/src/cmd/go/internal/fix/fix.go
@@ -0,0 +1,63 @@
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package fix implements the ``go fix'' command.
+package fix
+
+import (
+ "cmd/go/internal/base"
+ "cmd/go/internal/cfg"
+ "cmd/go/internal/load"
+ "cmd/go/internal/modload"
+ "cmd/go/internal/str"
+ "context"
+ "fmt"
+ "os"
+)
+
+var CmdFix = &base.Command{
+ Run: runFix,
+ UsageLine: "go fix [packages]",
+ Short: "update packages to use new APIs",
+ Long: `
+Fix runs the Go fix command on the packages named by the import paths.
+
+For more about fix, see 'go doc cmd/fix'.
+For more about specifying packages, see 'go help packages'.
+
+To run fix with specific options, run 'go tool fix'.
+
+See also: go fmt, go vet.
+ `,
+}
+
+func runFix(ctx context.Context, cmd *base.Command, args []string) {
+ pkgs := load.PackagesAndErrors(ctx, args)
+ w := 0
+ for _, pkg := range pkgs {
+ if pkg.Error != nil {
+ base.Errorf("%v", pkg.Error)
+ continue
+ }
+ pkgs[w] = pkg
+ w++
+ }
+ pkgs = pkgs[:w]
+
+ printed := false
+ for _, pkg := range pkgs {
+ if modload.Enabled() && pkg.Module != nil && !pkg.Module.Main {
+ if !printed {
+ fmt.Fprintf(os.Stderr, "go: not fixing packages in dependency modules\n")
+ printed = true
+ }
+ continue
+ }
+ // Use pkg.gofiles instead of pkg.Dir so that
+ // the command only applies to this package,
+ // not to packages in subdirectories.
+ files := base.RelPaths(pkg.InternalAllGoFiles())
+ base.Run(str.StringList(cfg.BuildToolexec, base.Tool("fix"), files))
+ }
+}