aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/import.go
diff options
context:
space:
mode:
authorBaokun Lee <bk@golangcn.org>2020-12-31 11:42:39 +0800
committerJay Conrod <jayconrod@google.com>2021-01-06 18:54:25 +0000
commitc9658bee93c169f6efd4654576bf8e9a920ec1de (patch)
tree61e15c72b8803e5ff5f5912df59c07f497897fa3 /src/cmd/go/internal/modload/import.go
parent4c668b25c6517ff12b61c11cad1f22ddc89a9791 (diff)
downloadgo-c9658bee93c169f6efd4654576bf8e9a920ec1de.tar.gz
go-c9658bee93c169f6efd4654576bf8e9a920ec1de.zip
cmd/go: make module suggestion more friendly
We are trying to avoid by not automatically updating go.mod. The suggestion should be that users actually add the dependencies they need, and the command in an easily copy-pastable form now. Fixes: #43430 Change-Id: I2227dab498fcd8d66184c94ebe9e776629ccadfd Reviewed-on: https://go-review.googlesource.com/c/go/+/280713 Run-TryBot: Baokun Lee <bk@golangcn.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com> Trust: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/import.go')
-rw-r--r--src/cmd/go/internal/modload/import.go12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go
index c16531e2f4..055878c528 100644
--- a/src/cmd/go/internal/modload/import.go
+++ b/src/cmd/go/internal/modload/import.go
@@ -31,10 +31,6 @@ type ImportMissingError struct {
Module module.Version
QueryErr error
- // inAll indicates whether Path is in the "all" package pattern,
- // and thus would be added by 'go mod tidy'.
- inAll bool
-
// isStd indicates whether we would expect to find the package in the standard
// library. This is normally true for all dotless import paths, but replace
// directives can cause us to treat the replaced paths as also being in
@@ -67,16 +63,14 @@ func (e *ImportMissingError) Error() string {
if !modfetch.IsZeroPseudoVersion(e.replaced.Version) {
suggestArg = e.replaced.String()
}
- return fmt.Sprintf("module %s provides package %s and is replaced but not required; try 'go get -d %s' to add it", e.replaced.Path, e.Path, suggestArg)
+ return fmt.Sprintf("module %s provides package %s and is replaced but not required; to add it:\n\tgo get %s", e.replaced.Path, e.Path, suggestArg)
}
suggestion := ""
if !HasModRoot() {
suggestion = ": working directory is not part of a module"
- } else if e.inAll {
- suggestion = "; try 'go mod tidy' to add it"
} else {
- suggestion = fmt.Sprintf("; try 'go get -d %s' to add it", e.Path)
+ suggestion = fmt.Sprintf("; to add it:\n\tgo get %s", e.Path)
}
return fmt.Sprintf("no required module provides package %s%s", e.Path, suggestion)
}
@@ -151,7 +145,7 @@ func (e *ImportMissingSumError) Error() string {
message = fmt.Sprintf("missing go.sum entry for module providing package %s", e.importPath)
}
if e.inAll {
- return message + "; try 'go mod tidy' to add it"
+ return message + "; to add it:\n\tgo mod tidy"
}
return message
}