//
// 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
"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)
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,
func init() {
cmdGraph.Flag.Var(&graphGo, "go", "")
+ cmdGraph.Flag.BoolVar(&cfg.BuildX, "x", false, "")
base.AddChdirFlag(&cmdGraph.Flag)
base.AddModCommonFlags(&cmdGraph.Flag)
}
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
# 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 --