From c43232f868439dcfd25d98501dafa5e695cd1d35 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Tue, 13 Jun 2023 11:25:28 -0400 Subject: [PATCH] cmd/digraph: improve examples using go list, mod Change-Id: Ib04b11b32f40f1602eb4cf0837e331b77511b6c5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/502875 gopls-CI: kokoro Run-TryBot: Alan Donovan TryBot-Bypass: Alan Donovan Reviewed-by: Robert Findley --- cmd/digraph/digraph.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/digraph/digraph.go b/cmd/digraph/digraph.go index 0e50ad18dcb..93130a018ce 100644 --- a/cmd/digraph/digraph.go +++ b/cmd/digraph/digraph.go @@ -63,18 +63,27 @@ shirt -> sweater, not shirt -> tie -> sweater. Example usage: -Using digraph with existing Go tools: +Show which clothes (see above) must be donned before a jacket: - $ go mod graph | digraph nodes # Operate on the Go module graph. - $ go list -m all | digraph nodes # Operate on the Go package graph. + $ digraph reverse jacket -Show the transitive closure of imports of the digraph tool itself: +Many tools can be persuaded to produce output in digraph format, +as in the following examples. - $ go list -f '{{.ImportPath}} {{join .Imports " "}}' ... | digraph forward golang.org/x/tools/cmd/digraph +Using an import graph produced by go list, show a path that indicates +why the gopls application depends on the cmp package: -Show which clothes (see above) must be donned before a jacket: + $ go list -f '{{.ImportPath}} {{join .Imports " "}}' -deps golang.org/x/tools/gopls | + digraph somepath golang.org/x/tools/gopls github.com/google/go-cmp/cmp - $ digraph reverse jacket +Show which packages in x/tools depend, perhaps indirectly, on the callgraph package: + + $ go list -f '{{.ImportPath}} {{join .Imports " "}}' -deps golang.org/x/tools/... | + digraph reverse golang.org/x/tools/go/callgraph + +Using a module graph produced by go mod, show all dependencies of the current module: + + $ go mod graph | digraph forward $(go list -m) */ package main // import "golang.org/x/tools/cmd/digraph"