diff options
author | Jay Conrod <jayconrod@google.com> | 2020-09-11 13:30:43 -0400 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2020-09-15 12:46:25 +0000 |
commit | 03875bd9bc112d25a4496f7ff22888f23a26baea (patch) | |
tree | 6f9fc4493cb0b775dabd1affa30d6e4209b153c3 /src/cmd/go/internal/modcmd/graph.go | |
parent | e3063636124d0e5b2d0fad7912a9c6810629f486 (diff) | |
download | go-03875bd9bc112d25a4496f7ff22888f23a26baea.tar.gz go-03875bd9bc112d25a4496f7ff22888f23a26baea.zip |
cmd/go: add modload.NeedRoot mode for commands that need module root
This makes error reporting a bit more consistent for 'go mod'
subcommands. Most of these commands only work in module mode when a
go.mod file is present.
Setting modload.ForceUseModules reports an error when GO111MODULE=off.
Setting modload.RootMode to modload.NeedRoot reports an error when no
go.mod file is present.
Change-Id: I1daa8d2971cb8658e0c804765839d903734a412e
Reviewed-on: https://go-review.googlesource.com/c/go/+/254369
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modcmd/graph.go')
-rw-r--r-- | src/cmd/go/internal/modcmd/graph.go | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/src/cmd/go/internal/modcmd/graph.go b/src/cmd/go/internal/modcmd/graph.go index a149b65605..3277548c23 100644 --- a/src/cmd/go/internal/modcmd/graph.go +++ b/src/cmd/go/internal/modcmd/graph.go @@ -13,7 +13,6 @@ import ( "sort" "cmd/go/internal/base" - "cmd/go/internal/cfg" "cmd/go/internal/modload" "golang.org/x/mod/module" @@ -39,14 +38,8 @@ func runGraph(ctx context.Context, cmd *base.Command, args []string) { if len(args) > 0 { base.Fatalf("go mod graph: graph takes no arguments") } - // Checks go mod expected behavior - if !modload.Enabled() { - if cfg.Getenv("GO111MODULE") == "off" { - base.Fatalf("go: modules disabled by GO111MODULE=off; see 'go help modules'") - } else { - base.Fatalf("go: cannot find main module; see 'go help modules'") - } - } + modload.ForceUseModules = true + modload.RootMode = modload.NeedRoot modload.LoadAllModules(ctx) reqs := modload.MinReqs() |