aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modcmd/graph.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2021-06-18 17:28:29 -0400
committerBryan C. Mills <bcmills@google.com>2021-06-21 21:21:09 +0000
commit1bd5a20e3c8a3a82e87487c381b76c97b720cd52 (patch)
tree938610ffc57146477399cbe437023b81f9517e29 /src/cmd/go/internal/modcmd/graph.go
parent761edf71f64bb2ef949ceb588822c47d2e1cc6ac (diff)
downloadgo-1bd5a20e3c8a3a82e87487c381b76c97b720cd52.tar.gz
go-1bd5a20e3c8a3a82e87487c381b76c97b720cd52.zip
cmd/go: add a -go flag to 'go mod graph'
For #46366 Change-Id: I8417e6e4dbb8cb56ff7afc16893a01b7bb938217 Reviewed-on: https://go-review.googlesource.com/c/go/+/329529 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modcmd/graph.go')
-rw-r--r--src/cmd/go/internal/modcmd/graph.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/cmd/go/internal/modcmd/graph.go b/src/cmd/go/internal/modcmd/graph.go
index 77853304e9..903bd9970f 100644
--- a/src/cmd/go/internal/modcmd/graph.go
+++ b/src/cmd/go/internal/modcmd/graph.go
@@ -18,7 +18,7 @@ import (
)
var cmdGraph = &base.Command{
- UsageLine: "go mod graph",
+ UsageLine: "go mod graph [-go=version]",
Short: "print module requirement graph",
Long: `
Graph prints the module requirement graph (with replacements applied)
@@ -26,12 +26,21 @@ in text form. Each line in the output has two space-separated fields: a module
and one of its requirements. Each module is identified as a string of the form
path@version, except for the main module, which has no @version suffix.
+The -go flag causes graph to report the module graph as loaded by by the
+given Go version, instead of the version indicated by the 'go' directive
+in the go.mod file.
+
See https://golang.org/ref/mod#go-mod-graph for more about 'go mod graph'.
`,
Run: runGraph,
}
+var (
+ graphGo goVersionFlag
+)
+
func init() {
+ cmdGraph.Flag.Var(&graphGo, "go", "")
base.AddModCommonFlags(&cmdGraph.Flag)
}
@@ -41,7 +50,7 @@ func runGraph(ctx context.Context, cmd *base.Command, args []string) {
}
modload.ForceUseModules = true
modload.RootMode = modload.NeedRoot
- mg := modload.LoadModGraph(ctx)
+ mg := modload.LoadModGraph(ctx, graphGo.String())
w := bufio.NewWriter(os.Stdout)
defer w.Flush()