r := newResolver(ctx, queries)
r.performLocalQueries(ctx)
r.performPathQueries(ctx)
+ r.performToolQueries(ctx)
for {
r.performWildcardQueries(ctx)
pathQueries []*query // package path literal queries in original order
wildcardQueries []*query // path wildcard queries in original order
patternAllQueries []*query // queries with the pattern "all"
+ toolQueries []*query // queries with the pattern "tool"
// Indexed "none" queries. These are also included in the slices above;
// they are indexed here to speed up noneForPath.
for _, q := range queries {
if q.pattern == "all" {
r.patternAllQueries = append(r.patternAllQueries, q)
+ } else if q.pattern == "tool" {
+ r.toolQueries = append(r.toolQueries, q)
} else if q.patternIsLocal {
r.localQueries = append(r.localQueries, q)
} else if q.isWildcard() {
})
}
+// performToolQueries populates the candidates for each query whose
+// pattern is "tool".
+func (r *resolver) performToolQueries(ctx context.Context) {
+ for _, q := range r.toolQueries {
+ for tool := range modload.MainModules.Tools() {
+ q.pathOnce(tool, func() pathSet {
+ pkgMods, err := r.queryPackages(ctx, tool, q.version, r.initialSelected)
+ return pathSet{pkgMods: pkgMods, err: err}
+ })
+ }
+ }
+}
+
// performPatternAllQueries populates the candidates for each query whose
// pattern is "all".
//
# test go get -tool
-go get -tool example.com/tools/cmd/hello
+go get -tool example.com/tools/cmd/hello@v1.0.0
cmp go.mod go.mod.want
+go get -u tool
+cmp go.mod go.mod.upgraded
+
# test -tool with @none
go get -tool example.com/tools/cmd/hello@none
cmp go.mod go.mod.gone
! go get -tool all
stderr 'go get -tool does not work with "all"'
+# test tool@none
+! go get tool@none
+stderr 'can''t request explicit version of "tool" pattern'
+
-- main.go --
package main
tool example.com/tools/cmd/hello
require example.com/tools v1.0.0 // indirect
+-- go.mod.upgraded --
+module example.com/foo
+
+go 1.24
+
+tool example.com/tools/cmd/hello
+
+require example.com/tools v1.1.0 // indirect
-- go.mod.gone --
module example.com/foo
go 1.24
-require example.com/tools v1.0.0 // indirect
+require example.com/tools v1.1.0 // indirect
-- go.mod.empty --
module example.com/foo