]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: enable -x in go mod graph
authorianwoolf <btw515wolf2@gmail.com>
Wed, 9 Nov 2022 08:52:41 +0000 (16:52 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 10 Nov 2022 21:10:42 +0000 (21:10 +0000)
Updates #35849

Change-Id: Ifa18e448c0d436c18d7204ac755cd36bc28cd612
Reviewed-on: https://go-review.googlesource.com/c/go/+/448935
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/alldocs.go
src/cmd/go/internal/modcmd/graph.go
src/cmd/go/testdata/script/mod_graph.txt
src/cmd/go/testdata/script/mod_graph_version.txt

index ceae79b5245ec50a08da972856e4f999e862a286..d493ecc726b6af44d9b698e6d4072e1b8c6107e1 100644 (file)
 //
 // 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
 // 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
index feed6a0005714fa6d4aefed8584c17421fde1522..555604dc84a3817d7085a580909e50f6775ff2e3 100644 (file)
@@ -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)
 }
index 07968f531d22ea828082fde15a09e530c1761972..8d514392e4c1718f9023d24929a44f2fa9dd5f31 100644 (file)
@@ -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
index f9a73f4617b34366cb2ffd146ad969614034f641..ed7e399418c86b2cd1c883868e0fb97b4b2e27ad 100644 (file)
@@ -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 --