Skip to content

Commit

Permalink
cmd/digraph: improve examples using go list, mod
Browse files Browse the repository at this point in the history
Change-Id: Ib04b11b32f40f1602eb4cf0837e331b77511b6c5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/502875
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Bypass: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
adonovan committed Jun 13, 2023
1 parent 6e1595c commit c43232f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cmd/digraph/digraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit c43232f

Please sign in to comment.