}
}
- mods, err := modload.ListModules(ctx, args, *listU, *listVersions, *listRetracted)
+ var mode modload.ListMode
+ if *listU {
+ mode |= modload.ListU | modload.ListRetracted
+ }
+ if *listRetracted {
+ mode |= modload.ListRetracted
+ }
+ if *listVersions {
+ mode |= modload.ListVersions
+ if *listRetracted {
+ mode |= modload.ListRetractedVersions
+ }
+ }
+ mods, err := modload.ListModules(ctx, args, mode)
if !*listE {
for _, m := range mods {
if m.Error != nil {
}
if len(args) > 0 {
- listU := false
- listVersions := false
- rmods, err := modload.ListModules(ctx, args, listU, listVersions, *listRetracted)
+ var mode modload.ListMode
+ if *listRetracted {
+ mode |= modload.ListRetracted
+ }
+ rmods, err := modload.ListModules(ctx, args, mode)
if err != nil && !*listE {
base.Errorf("go list -retracted: %v", err)
}
}
rs := LoadModFile(ctx)
- listRetracted := false
- return moduleInfo(ctx, rs, m, listRetracted)
+ return moduleInfo(ctx, rs, m, 0)
}
func ModuleInfo(ctx context.Context, path string) *modinfo.ModulePublic {
return nil
}
- listRetracted := false
if i := strings.Index(path, "@"); i >= 0 {
m := module.Version{Path: path[:i], Version: path[i+1:]}
- return moduleInfo(ctx, nil, m, listRetracted)
+ return moduleInfo(ctx, nil, m, 0)
}
rs := LoadModFile(ctx)
}
}
- return moduleInfo(ctx, rs, module.Version{Path: path, Version: v}, listRetracted)
+ return moduleInfo(ctx, rs, module.Version{Path: path, Version: v}, 0)
}
// addUpdate fills in m.Update if an updated version is available.
// moduleInfo returns information about module m, loaded from the requirements
// in rs (which may be nil to indicate that m was not loaded from a requirement
// graph).
-func moduleInfo(ctx context.Context, rs *Requirements, m module.Version, listRetracted bool) *modinfo.ModulePublic {
+func moduleInfo(ctx context.Context, rs *Requirements, m module.Version, mode ListMode) *modinfo.ModulePublic {
if m == Target {
info := &modinfo.ModulePublic{
Path: m.Path,
}
}
- if listRetracted {
+ if mode&ListRetracted != 0 {
addRetraction(ctx, m)
}
}
"golang.org/x/mod/module"
)
+type ListMode int
+
+const (
+ ListU ListMode = 1 << iota
+ ListRetracted
+ ListVersions
+ ListRetractedVersions
+)
+
// ListModules returns a description of the modules matching args, if known,
// along with any error preventing additional matches from being identified.
//
// The returned slice can be nonempty even if the error is non-nil.
-func ListModules(ctx context.Context, args []string, listU, listVersions, listRetracted bool) ([]*modinfo.ModulePublic, error) {
- rs, mods, err := listModules(ctx, LoadModFile(ctx), args, listVersions, listRetracted)
+func ListModules(ctx context.Context, args []string, mode ListMode) ([]*modinfo.ModulePublic, error) {
+ rs, mods, err := listModules(ctx, LoadModFile(ctx), args, mode)
type token struct{}
sem := make(chan token, runtime.GOMAXPROCS(0))
- if listU || listVersions || listRetracted {
+ if mode != 0 {
for _, m := range mods {
add := func(m *modinfo.ModulePublic) {
sem <- token{}
go func() {
- if listU {
+ if mode&ListU != 0 {
addUpdate(ctx, m)
}
- if listVersions {
- addVersions(ctx, m, listRetracted)
+ if mode&ListVersions != 0 {
+ addVersions(ctx, m, mode&ListRetractedVersions != 0)
}
- if listRetracted || listU {
+ if mode&ListRetracted != 0 {
addRetraction(ctx, m)
}
<-sem
return mods, err
}
-func listModules(ctx context.Context, rs *Requirements, args []string, listVersions, listRetracted bool) (_ *Requirements, mods []*modinfo.ModulePublic, mgErr error) {
+func listModules(ctx context.Context, rs *Requirements, args []string, mode ListMode) (_ *Requirements, mods []*modinfo.ModulePublic, mgErr error) {
var mg *ModuleGraph
if go117LazyTODO {
// Pull the args-loop below into another (new) loop.
}
if len(args) == 0 {
- return rs, []*modinfo.ModulePublic{moduleInfo(ctx, rs, Target, listRetracted)}, mgErr
+ return rs, []*modinfo.ModulePublic{moduleInfo(ctx, rs, Target, mode)}, mgErr
}
matchedModule := map[module.Version]bool{}
if arg == "all" || strings.Contains(arg, "...") {
base.Fatalf("go: cannot match %q: %v", arg, ErrNoModRoot)
}
- if !listVersions && !strings.Contains(arg, "@") {
+ if mode&ListVersions == 0 && !strings.Contains(arg, "@") {
base.Fatalf("go: cannot match %q without -versions or an explicit version: %v", arg, ErrNoModRoot)
}
}
}
allowed := CheckAllowed
- if IsRevisionQuery(vers) || listRetracted {
+ if IsRevisionQuery(vers) || mode&ListRetracted != 0 {
// Allow excluded and retracted versions if the user asked for a
// specific revision or used 'go list -retracted'.
allowed = nil
// *Requirements instead.
var noRS *Requirements
- mod := moduleInfo(ctx, noRS, module.Version{Path: path, Version: info.Version}, listRetracted)
+ mod := moduleInfo(ctx, noRS, module.Version{Path: path, Version: info.Version}, mode)
mods = append(mods, mod)
continue
}
continue
}
if v != "none" {
- mods = append(mods, moduleInfo(ctx, rs, module.Version{Path: arg, Version: v}, listRetracted))
+ mods = append(mods, moduleInfo(ctx, rs, module.Version{Path: arg, Version: v}, mode))
} else if cfg.BuildMod == "vendor" {
// In vendor mode, we can't determine whether a missing module is “a
// known dependency” because the module graph is incomplete.
Path: arg,
Error: modinfoError(arg, "", errors.New("can't resolve module using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)")),
})
- } else if listVersions {
+ } else if mode&ListVersions != 0 {
// Don't make the user provide an explicit '@latest' when they're
// explicitly asking what the available versions are. Instead, return a
// module with version "none", to which we can add the requested list.
matched = true
if !matchedModule[m] {
matchedModule[m] = true
- mods = append(mods, moduleInfo(ctx, rs, m, listRetracted))
+ mods = append(mods, moduleInfo(ctx, rs, m, mode))
}
}
}