From: ianwoolf Date: Wed, 9 Nov 2022 08:52:41 +0000 (+0800) Subject: cmd/go: enable -x in go mod graph X-Git-Tag: go1.20rc1~313 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fcecf3e1fa318d4c3e8f2142d17bb2e481e94f9d;p=gostls13.git cmd/go: enable -x in go mod graph Updates #35849 Change-Id: Ifa18e448c0d436c18d7204ac755cd36bc28cd612 Reviewed-on: https://go-review.googlesource.com/c/go/+/448935 Reviewed-by: Bryan Mills Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills Reviewed-by: Michael Knyszek TryBot-Result: Gopher Robot --- diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index ceae79b524..d493ecc726 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -1248,7 +1248,7 @@ // // Usage: // -// go mod graph [-go=version] +// go mod graph [-go=version] [-x] // // Graph prints the module requirement graph (with replacements applied) // in text form. Each line in the output has two space-separated fields: a module @@ -1259,6 +1259,8 @@ // given Go version, instead of the version indicated by the 'go' directive // in the go.mod file. // +// The -x flag causes graph to print the commands graph executes. +// // See https://golang.org/ref/mod#go-mod-graph for more about 'go mod graph'. // // # Initialize new module in current directory diff --git a/src/cmd/go/internal/modcmd/graph.go b/src/cmd/go/internal/modcmd/graph.go index feed6a0005..555604dc84 100644 --- a/src/cmd/go/internal/modcmd/graph.go +++ b/src/cmd/go/internal/modcmd/graph.go @@ -12,13 +12,14 @@ import ( "os" "cmd/go/internal/base" + "cmd/go/internal/cfg" "cmd/go/internal/modload" "golang.org/x/mod/module" ) var cmdGraph = &base.Command{ - UsageLine: "go mod graph [-go=version]", + UsageLine: "go mod graph [-go=version] [-x]", Short: "print module requirement graph", Long: ` Graph prints the module requirement graph (with replacements applied) @@ -30,6 +31,8 @@ The -go flag causes graph to report the module graph as loaded by the given Go version, instead of the version indicated by the 'go' directive in the go.mod file. +The -x flag causes graph to print the commands graph executes. + See https://golang.org/ref/mod#go-mod-graph for more about 'go mod graph'. `, Run: runGraph, @@ -41,6 +44,7 @@ var ( func init() { cmdGraph.Flag.Var(&graphGo, "go", "") + cmdGraph.Flag.BoolVar(&cfg.BuildX, "x", false, "") base.AddChdirFlag(&cmdGraph.Flag) base.AddModCommonFlags(&cmdGraph.Flag) } diff --git a/src/cmd/go/testdata/script/mod_graph.txt b/src/cmd/go/testdata/script/mod_graph.txt index 07968f531d..8d514392e4 100644 --- a/src/cmd/go/testdata/script/mod_graph.txt +++ b/src/cmd/go/testdata/script/mod_graph.txt @@ -4,6 +4,11 @@ go mod graph stdout '^m rsc.io/quote@v1.5.2$' stdout '^rsc.io/quote@v1.5.2 rsc.io/sampler@v1.3.0$' ! stdout '^m rsc.io/sampler@v1.3.0$' +! stderr 'get '$GOPROXY + +rm $GOPATH/pkg/mod/cache/download/rsc.io/quote +go mod graph -x +stderr 'get '$GOPROXY -- go.mod -- module m diff --git a/src/cmd/go/testdata/script/mod_graph_version.txt b/src/cmd/go/testdata/script/mod_graph_version.txt index f9a73f4617..ed7e399418 100644 --- a/src/cmd/go/testdata/script/mod_graph_version.txt +++ b/src/cmd/go/testdata/script/mod_graph_version.txt @@ -57,7 +57,7 @@ stdout '^example.net/requireincompatible@v0.1.0 example.com/retract/incompatible # Unsupported go versions should be rejected, since we don't know # what versions they would report. ! go mod graph -go=1.99999999999 -stderr '^invalid value "1\.99999999999" for flag -go: maximum supported Go version is '$goversion'\nusage: go mod graph \[-go=version\]\nRun ''go help mod graph'' for details.$' +stderr '^invalid value "1\.99999999999" for flag -go: maximum supported Go version is '$goversion'\nusage: go mod graph \[-go=version\] \[-x\]\nRun ''go help mod graph'' for details.$' -- go.mod --