aboutsummaryrefslogtreecommitdiff
path: root/cmd/internal
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2025-05-20 13:27:53 -0400
committerMichael Matloob <matloob@google.com>2025-05-20 11:50:40 -0700
commite960035a5a535533c6bff3a2bf423d2d8d413b36 (patch)
tree58909beb92aa53aefb64f61825103959c0bab5aa /cmd/internal
parentef1cfc531f532653ec7571b0edce9aa903ea1136 (diff)
downloadgo-x-pkgsite-e960035a5a535533c6bff3a2bf423d2d8d413b36.tar.xz
cmd/internal/pkgsite: add AllowNoModules option to ServerConfig
If the user is outside of any modules, they should be able to still get documentation for the standard library. Allow no matching modules so we don't exit the command if no modules were found. For golang/go#68106 Change-Id: Ie9a06e1a3b055e3d13957019d06677f5aed46f4d Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/674436 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Michael Matloob <matloob@google.com> kokoro-CI: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'cmd/internal')
-rw-r--r--cmd/internal/pkgsite/server.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/cmd/internal/pkgsite/server.go b/cmd/internal/pkgsite/server.go
index f97e3505..d35255b9 100644
--- a/cmd/internal/pkgsite/server.go
+++ b/cmd/internal/pkgsite/server.go
@@ -41,6 +41,7 @@ type ServerConfig struct {
DevMode bool
DevModeStaticDir string
GoRepoPath string
+ AllowNoModules bool
Proxy *proxy.Client // client, or nil; controlled by the -proxy flag
}
@@ -68,7 +69,7 @@ func BuildServer(ctx context.Context, serverCfg ServerConfig) (*frontend.Server,
}
} else {
var err error
- cfg.dirs, err = getModuleDirs(ctx, serverCfg.Paths)
+ cfg.dirs, err = getModuleDirs(ctx, serverCfg.Paths, serverCfg.AllowNoModules)
if err != nil {
return nil, fmt.Errorf("searching modules: %v", err)
}
@@ -121,7 +122,7 @@ func BuildServer(ctx context.Context, serverCfg ServerConfig) (*frontend.Server,
//
// An error is returned if any operations failed unexpectedly, or if no
// requested directories contain any valid modules.
-func getModuleDirs(ctx context.Context, dirs []string) (map[string][]frontend.LocalModule, error) {
+func getModuleDirs(ctx context.Context, dirs []string, allowNoModules bool) (map[string][]frontend.LocalModule, error) {
dirModules := make(map[string][]frontend.LocalModule)
for _, dir := range dirs {
output, err := runGo(dir, "list", "-m", "-json")
@@ -143,7 +144,7 @@ func getModuleDirs(ctx context.Context, dirs []string) (map[string][]frontend.Lo
dirModules[dir] = modules
}
}
- if len(dirs) > 0 && len(dirModules) == 0 {
+ if len(dirs) > 0 && len(dirModules) == 0 && !allowNoModules {
return nil, fmt.Errorf("no modules in any of the requested directories")
}
return dirModules, nil