- Notifications
You must be signed in to change notification settings - Fork0
License
molior-dbs/golang-github-kylebanks-depth
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
depth is tool to retrieve and visualize Go source code dependency trees.
Download the appropriate binary for your platform from theReleases page, or:
go get github.com/KyleBanks/depth/cmd/depth
depth can be used as a standalone command-line application, or as a package within your own project.
Simply executedepth with one or more package names to visualize. You can use the fully qualified import path of the package, like so:
$ depth github.com/KyleBanks/depth/cmd/depthgithub.com/KyleBanks/depth/cmd/depth ├ encoding/json ├ flag ├ fmt ├ io ├ log ├ os ├ strings └ github.com/KyleBanks/depth ├ fmt ├ go/build ├ path ├ sort └ strings12 dependencies (11 internal, 1 external, 0 testing).
Or you can use a relative path, for example:
$ depth.$ depth ./cmd/depth$ depth ../You can also usedepth on the Go standard library:
$ depth stringsstrings ├ errors ├ io ├ unicode └ unicode/utf85 dependencies (5 internal, 0 external, 0 testing).
Visualizing multiple packages at a time is supported by simply naming the packages you'd like to visualize:
$ depth strings github.com/KyleBanks/depth strings ├ errors ├ io ├ unicode └ unicode/utf85 dependencies (5 internal, 0 external, 0 testing).github.com/KyleBanks/depth ├ fmt ├ go/build ├ path ├ sort └ strings7 dependencies (7 internal, 0 external, 0 testing).
By default,depth only resolves the top level of dependencies for standard library packages, however you can use the-internal flag to visualize all internal dependencies:
$ depth -internal stringsstrings ├ errors ├ io ├ errors └ sync ├ internal/race └ unsafe ├ runtime ├ runtime/internal/atomic └ unsafe ├ runtime/internal/sys └ unsafe ├ sync/atomic └ unsafe └ unsafe ├ unicode └ unicode/utf812 dependencies (12 internal, 0 external, 0 testing).
The-max flag limits the dependency tree to the maximum depth provided. For example, if you supply-max 1 on thedepth package, your output would look like so:
$ depth -max 1 github.com/KyleBanks/depth/cmd/depthgithub.com/KyleBanks/depth/cmd/depth ├ encoding/json ├ flag ├ fmt ├ io ├ log ├ os ├ strings └ github.com/KyleBanks/depth7 dependencies (6 internal, 1 external, 0 testing).The-max flag is particularly useful in conjunction with the-internal flag which can lead to very deep dependency trees.
By default,depth ignores dependencies that are only required for testing. However, you can view test dependencies using the-test flag:
$ depth -test stringsstrings ├ bytes ├ errors ├ fmt ├ io ├ io/ioutil ├ math/rand ├ reflect ├ sync ├ testing ├ unicode ├ unicode/utf8 └ unsafe13 dependencies (13 internal, 0 external, 8 testing).
The-explain flag instructsdepth to print import chains in which thetarget-package is found:
$ depth -explain strings github.com/KyleBanks/depth/cmd/depthgithub.com/KyleBanks/depth/cmd/depth -> stringsgithub.com/KyleBanks/depth/cmd/depth -> github.com/KyleBanks/depth -> strings
The-json flag instructsdepth to output dependencies in JSON format:
$ depth -json github.com/KyleBanks/depth/cmd/depth{"name":"github.com/KyleBanks/depth/cmd/depth","deps": [ {"name":"encoding/json","internal": true,"deps": null }, ... {"name":"github.com/KyleBanks/depth","internal": false,"deps": [ {"name":"go/build","internal": true,"deps": null }, ... ] } ]}Thedepth package can easily be used to retrieve the dependency tree for a particular package in your own project. For example, here's how you would retrieve the dependency tree for thestrings package:
import"github.com/KyleBanks/depth"vart depth.Treeerr:=t.Resolve("strings")iferr!=nil {log.Fatal(err)}// Output: "'strings' has 4 dependencies."log.Printf("'%v' has %v dependencies.",t.Root.Name,len(t.Root.Deps))
For additional customization, simply set the appropriate flags on theTree before resolving:
import"github.com/KyleBanks/depth"t:= depth.Tree {ResolveInternal:true,ResolveTest:true,MaxDepth:10,}err:=t.Resolve("strings")
depth was developed byKyle Banks.
depth is available under theMIT license.
About
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors5
Uh oh!
There was an error while loading.Please reload this page.