]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: do not print "go install" in errors from other commands
authorRuss Cox <rsc@golang.org>
Thu, 2 Nov 2017 13:46:13 +0000 (09:46 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 3 Nov 2017 17:45:06 +0000 (17:45 +0000)
Fixes #20251.

Change-Id: I312a9534248668c8b3b4cf979591ed1a49e509e1
Reviewed-on: https://go-review.googlesource.com/75474
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/go/internal/cfg/cfg.go
src/cmd/go/internal/work/build.go
src/cmd/go/internal/work/exec.go
src/cmd/go/main.go

index 3c7b918523506fdea315b52b6444e84e3ce6e19d..5f93f39f904c88f53b157edcf2221f5042e9f5a2 100644 (file)
@@ -38,6 +38,8 @@ var (
        BuildWork              bool // -work flag
        BuildX                 bool // -x flag
 
+       CmdName string // "build", "install", "list", etc.
+
        DebugActiongraph string // -debug-actiongraph flag (undocumented, unstable)
 )
 
index 0e9c878556083e0d8da699d787cce5697296b378..694cf518c494524a59f576c103bd3d1d4729e996 100644 (file)
@@ -550,14 +550,14 @@ func InstallPackages(args []string, forGet bool) {
                if p.Target == "" && (!p.Standard || p.ImportPath != "unsafe") {
                        switch {
                        case p.Internal.GobinSubdir:
-                               base.Errorf("go install: cannot install cross-compiled binaries when GOBIN is set")
+                               base.Errorf("go %s: cannot install cross-compiled binaries when GOBIN is set", cfg.CmdName)
                        case p.Internal.Cmdline:
-                               base.Errorf("go install: no install location for .go files listed on command line (GOBIN not set)")
+                               base.Errorf("go %s: no install location for .go files listed on command line (GOBIN not set)", cfg.CmdName)
                        case p.ConflictDir != "":
-                               base.Errorf("go install: no install location for %s: hidden by %s", p.Dir, p.ConflictDir)
+                               base.Errorf("go %s: no install location for %s: hidden by %s", cfg.CmdName, p.Dir, p.ConflictDir)
                        default:
-                               base.Errorf("go install: no install location for directory %s outside GOPATH\n"+
-                                       "\tFor more details see: 'go help gopath'", p.Dir)
+                               base.Errorf("go %s: no install location for directory %s outside GOPATH\n"+
+                                       "\tFor more details see: 'go help gopath'", cfg.CmdName, p.Dir)
                        }
                }
        }
index ae69642e46453a32269ee5adab4860ef79cd4c0a..9daa58577805f195071f3c28f6056cf004de1a25 100644 (file)
@@ -945,7 +945,7 @@ func BuildInstallFunc(b *Builder, a *Action) (err error) {
                        if a.Package != nil {
                                sep, path = " ", a.Package.ImportPath
                        }
-                       err = fmt.Errorf("go install%s%s: %v", sep, path, err)
+                       err = fmt.Errorf("go %s%s%s: %v", cfg.CmdName, sep, path, err)
                }
        }()
 
index f5b64869ea15bb947177a43d6b8a929b6491b58f..b7e4034152ab7e1220a8382d6d709823ec439594 100644 (file)
@@ -77,6 +77,7 @@ func main() {
                base.Usage()
        }
 
+       cfg.CmdName = args[0] // for error messages
        if args[0] == "help" {
                help.Help(args[1:])
                return