Skip to content
forked from vc60er/deptree

show golang dependence like tree

Notifications You must be signed in to change notification settings

gen2thomas/deptree

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deptree

show golang dependence like tree

How to get it

➜ go install github.com/vc60er/deptree@latest
➜ export PATH=$PATH:$GOPATH/bin

Usage

params

Usage of deptree:
  -a  show all dependencies, also without upgrade and point out duplicated children
  -c  upgrade candidates will be marked yellow
  -d int
      max depth of dependencies (default 3)
  -f  force show of each occurrence of a child branch in tree (can cause hang)
  -graph string
      path to file created e.g. by 'go mod graph > grapphfile.txt'
  -json
      print JSON instead of tree
  -t  visualize trimmed tree by '└─...'
  -upgrade string
      path to file created e.g. by 'go list -u -m -json all > upgradefile.txt'
  -v int
      be more verbose

example

➜  redis git:(master) go mod graph | deptree -d 2 -t -a
call 'go list -u -m -json all', be patient...
dependency tree with depth 2 for package: gobot.io/x/gobot, least 99 trimmed item(s)
* tree of duplicate children not drawn (-f not set)
* 12 duplicate child trees replaced by links

gobot.io/x/gobot (go1.17)
 ├── github.com/bmizerany/[email protected]
 ├── github.com/cpuguy83/go-md2man/[email protected] (go1.11)
 │    └── github.com/russross/blackfriday/[email protected]
 ├── github.com/creack/[email protected] (go1.13)
 ├── github.com/davecgh/[email protected]
 ├── github.com/donovanhide/[email protected]
 ├── github.com/eclipse/[email protected] (go1.14) => [v1.4.2]
 │    ├── github.com/gorilla/[email protected] => [v1.5.0] (go1.12)
 │    ├── golang.org/x/[email protected] => [v0.10.0]
 │    │    └── 3 more ...
 │    └── golang.org/x/[email protected] => [v0.2.0]
 ├── github.com/fatih/[email protected]
 ├── <2> github.com/go-ole/[email protected] (go1.12)
 │    └── golang.org/x/[email protected] => [v0.8.0]
 ├── github.com/godbus/dbus/[email protected] (go1.12)
 ├── github.com/gofrs/[email protected]+incompatible => [v4.4.0+incompatible]
 ├── <7> github.com/golang/[email protected] (go1.9) => [v1.5.3]
 │    ├── <8> github.com/google/[email protected] (go1.8) => [v0.5.9]
 │    │    └── 1 more ...
 │    └── google.golang.org/[email protected] => [v1.30.0]
 │         └── 1 more ...
 ├── github.com/gorilla/[email protected] (go1.12)
 ├── github.com/hashicorp/[email protected]
 ├── github.com/hashicorp/[email protected] (go1.13)
 │    └── github.com/hashicorp/[email protected] => [v1.1.0]
 ├── github.com/hybridgroup/[email protected]
 ├── github.com/hybridgroup/[email protected]
 ├── <10> github.com/muka/[email protected] (go1.14) => [v0.0.0-20221213043340-85dc80edc4e1]
 │    ├── github.com/fatih/[email protected]
 │    ├── github.com/godbus/dbus/[email protected] => [v5.1.0] (go1.12)
 │    ├── github.com/niemeyer/[email protected] (go1.12)
 │    │    └── 1 more ...
 │    ├── github.com/pkg/[email protected]
 │    ├── github.com/sirupsen/[email protected] => [v1.9.0] (go1.13)
 │    │    └── 5 more ...
 │    ├── github.com/stretchr/[email protected] => [v1.8.2]
 │    │    └── 4 more ...
 │    ├── github.com/suapapa/[email protected] (go1.14)
 │    │    └── 2 more ...
 │    ├── golang.org/x/[email protected] => [v0.8.0]
 │    ├── golang.org/x/[email protected] => [v0.9.1]
 │    │    └── 5 more ...
 │    └── gopkg.in/[email protected] => [v1.0.0-20201130134442-10cb98267c6c]
 ├── github.com/nats-io/nats-server/[email protected] => [v2.9.16]
 │    ├── github.com/golang/[email protected] => [v1.5.3]
 │    ├── github.com/nats-io/[email protected] => [v1.2.2]
 │    │    └── 1 more ...
 │    ├── github.com/nats-io/[email protected] => [v1.25.0]
 │    │    └── 2 more ...
 │    ├── github.com/nats-io/[email protected] => [v0.4.4]
 │    │    └── 1 more ...
 │    ├── github.com/nats-io/[email protected]
 │    ├── golang.org/x/[email protected] => [v0.9.0]
 │    │    └── 2 more ...
 │    └── golang.org/x/[email protected] => [v0.8.0]
 ├── github.com/nats-io/[email protected] (go1.16) => [v1.25.0]
 │    ├── github.com/nats-io/[email protected] (go1.16) => [v0.4.4], see <1> for 1 children (branch 'gobot.io/x/gobot' level 1)
 │    └── github.com/nats-io/[email protected]
 ├── <1> github.com/nats-io/[email protected] (go1.16) => [v0.4.4]
 │    └── golang.org/x/[email protected] => [v0.9.0]
 │         └── 3 more ...
 ├── github.com/nats-io/[email protected]
 ├── github.com/pkg/[email protected]
 ├── github.com/pmezard/[email protected]
 ├── github.com/russross/blackfriday/[email protected]
 ├── github.com/saltosystems/[email protected] (go1.18) => [v0.0.0-20230510070731-e096b9afa761]
 │    ├── github.com/glerchundi/[email protected]
 │    ├── github.com/go-kit/[email protected] (go1.17)
 │    │    └── 1 more ...
 │    ├── github.com/go-ole/[email protected] (go1.12), see <2> for 1 children (branch 'gobot.io/x/gobot' level 1)
 │    ├── github.com/peterbourgon/ff/[email protected] (go1.16) => [v3.3.1]
 │    │    └── 2 more ...
 │    ├── github.com/stretchr/[email protected] => [v1.8.2]
 │    │    └── 4 more ...
 │    ├── github.com/tdakkota/[email protected] (go1.16)
 │    │    └── 2 more ...
 │    ├── golang.org/x/[email protected] (go1.17) => [v0.9.1]
 │    │    └── 6 more ...
 │    ├── github.com/davecgh/[email protected]
 │    ├── github.com/go-logfmt/[email protected] (go1.17) => [v0.6.0]
 │    ├── github.com/pmezard/[email protected]
 │    ├── golang.org/x/[email protected] (go1.17) => [v0.10.0]
 │    │    └── 2 more ...
 │    ├── golang.org/x/[email protected] => [v0.8.0]
 │    └── gopkg.in/[email protected], see <3> for 1 children (branch 'gobot.io/x/gobot' level 1)
 ├── github.com/sigurn/[email protected] (go1.17)
 ├── <11> github.com/sirupsen/[email protected] (go1.13)
 │    ├── github.com/davecgh/[email protected]
 │    ├── <5> github.com/stretchr/[email protected] => [v1.8.2]
 │    │    └── 4 more ...
 │    └── golang.org/x/[email protected] => [v0.8.0]
 ├── github.com/stretchr/[email protected] (go1.13) => [v1.8.2]
 │    ├── github.com/davecgh/[email protected]
 │    ├── github.com/pmezard/[email protected]
 │    ├── github.com/stretchr/[email protected] (go1.12) => [v0.5.0]
 │    │    └── 2 more ...
 │    └── gopkg.in/[email protected], see <3> for 1 children (branch 'gobot.io/x/gobot' level 1)
 ├── <12> github.com/tinygo-org/[email protected] (go1.14)
 │    └── github.com/sirupsen/[email protected] => [v1.9.0] (go1.13)
 │         └── 5 more ...
 ├── github.com/urfave/[email protected] (go1.11) => [v1.22.13]
 │    ├── github.com/BurntSushi/[email protected] => [v1.2.1]
 │    ├── github.com/cpuguy83/go-md2man/[email protected] => [v2.0.2] (go1.11)
 │    │    └── 3 more ...
 │    └── <4> gopkg.in/[email protected] => [v2.4.0]
 │         └── 1 more ...
 ├── github.com/veandco/[email protected] (go1.15) => [v0.4.35]
 ├── github.com/warthog618/[email protected] (go1.17) => [v0.8.1]
 │    ├── github.com/pilebones/[email protected] => [v0.9.0]
 │    ├── github.com/spf13/[email protected] (go1.12) => [v1.7.0]
 │    ├── github.com/spf13/[email protected] (go1.12)
 │    ├── github.com/stretchr/[email protected] => [v1.8.2]
 │    ├── github.com/warthog618/[email protected] (go1.11) => [v0.5.1]
 │    ├── golang.org/x/[email protected] => [v0.8.0]
 │    ├── gopkg.in/[email protected] => [v1.0.0-20201130134442-10cb98267c6c]
 │    ├── github.com/davecgh/[email protected]
 │    ├── github.com/fsnotify/[email protected] => [v1.6.0]
 │    ├── github.com/inconshreveable/[email protected] => [v1.1.0]
 │    ├── github.com/pkg/[email protected] => [v0.9.1]
 │    ├── github.com/pmezard/[email protected]
 │    └── gopkg.in/[email protected] => [v2.4.0], see <4> for 1 children (branch 'github.com/urfave/[email protected]' level 2)
 ├── go.bug.st/[email protected] (go1.17) => [v1.5.0]
 │    ├── github.com/creack/[email protected] (go1.13)
 │    ├── github.com/stretchr/[email protected] => [v1.8.2], see <5> for 1 children (branch 'github.com/sirupsen/[email protected]' level 2)
 │    ├── golang.org/x/[email protected] => [v0.8.0]
 │    ├── github.com/davecgh/[email protected] => [v1.1.1]
 │    ├── github.com/pmezard/[email protected]
 │    └── gopkg.in/[email protected] => [v3.0.1]
 │         └── 1 more ...
 ├── gocv.io/x/[email protected] (go1.13) => [v0.32.1]
 │    ├── github.com/hybridgroup/[email protected]
 │    └── github.com/pascaldekloe/[email protected] => [v0.1.1]
 ├── golang.org/x/[email protected] (go1.17) => [v0.9.0]
 │    ├── golang.org/x/[email protected] (go1.17) => [v0.10.0], see <6> for 3 children (branch 'gobot.io/x/gobot' level 1)
 │    ├── golang.org/x/[email protected] (go1.17) => [v0.8.0]
 │    ├── golang.org/x/[email protected] (go1.17) => [v0.8.0]
 │    └── golang.org/x/[email protected] (go1.17) => [v0.9.0]
 ├── <6> golang.org/x/[email protected] (go1.17) => [v0.10.0]
 │    ├── golang.org/x/[email protected] (go1.17) => [v0.8.0]
 │    ├── golang.org/x/[email protected] (go1.17) => [v0.8.0]
 │    └── golang.org/x/[email protected] (go1.17) => [v0.9.0]
 ├── golang.org/x/[email protected] => [v0.2.0]
 ├── golang.org/x/[email protected] (go1.17) => [v0.8.0]
 ├── google.golang.org/[email protected] (go1.11) => [v1.30.0]
 │    ├── github.com/golang/[email protected] (go1.9) => [v1.5.3], see <7> for 2 children (branch 'gobot.io/x/gobot' level 1)
 │    └── github.com/google/[email protected] (go1.8) => [v0.5.9], see <8> for 1 children (branch 'github.com/golang/[email protected]' level 2)
 ├── <3> gopkg.in/[email protected]
 │    └── gopkg.in/[email protected] => [v1.0.0-20201130134442-10cb98267c6c]
 ├── <9> periph.io/x/conn/[email protected] (go1.13) => [v3.7.0]
 │    └── github.com/jonboulle/[email protected] (go1.13) => [v0.4.0]
 ├── periph.io/x/host/[email protected] (go1.13) => [v3.8.2]
 │    ├── periph.io/x/conn/[email protected] (go1.13) => [v3.7.0], see <9> for 1 children (branch 'gobot.io/x/gobot' level 1)
 │    └── periph.io/x/[email protected] (go1.13) => [v0.1.0]
 └── tinygo.org/x/[email protected] (go1.15)
      ├── github.com/go-ole/[email protected] (go1.12), see <2> for 1 children (branch 'gobot.io/x/gobot' level 1)
      ├── github.com/godbus/dbus/[email protected] => [v5.1.0] (go1.12)
      ├── github.com/muka/[email protected] (go1.14) => [v0.0.0-20221213043340-85dc80edc4e1], see <10> for 10 children (branch 'gobot.io/x/gobot' level 1)
      ├── github.com/saltosystems/[email protected] => [v0.0.0-20230510070731-e096b9afa761]
      │    └── 13 more ...
      ├── github.com/sirupsen/[email protected] (go1.13), see <11> for 3 children (branch 'gobot.io/x/gobot' level 1)
      ├── github.com/tinygo-org/[email protected] (go1.14), see <12> for 1 children (branch 'gobot.io/x/gobot' level 1)
      ├── golang.org/x/[email protected] => [v0.9.0]
      │    └── 4 more ...
      ├── golang.org/x/[email protected] => [v0.8.0]
      ├── tinygo.org/x/[email protected] (go1.15) => [v0.24.0]
      │    └── 6 more ...
      └── tinygo.org/x/[email protected] (go1.15) => [v0.2.0]
           └── 4 more ...

Variant: file for dependency graph

Alternatively a file with the content can be provided.

cd into the package root folder (contains go.mod) and run:

go mod graph > graphfile.txt

deptree -graph=graphfile.txt

Variant: file for module list

Alternatively a file with the content can be provided

cd into the package root folder (contains go.mod) and run:

go list -u -m -json all > upgradefile.txt

go mod graph | deptree -upgrade=upgradefile.txt

Variant: both files used

Relative paths can be used also.

deptree -graph=data/graphfile.txt -upgrade=data/upgradefile.txt

Duplicate occurrence of children

More than one occurrence of an item at different levels of the tree is possible. This occurs very likely for projects with many dependencies (count of imports in go.mod file). deptree handles this in the following way to avoid duplicate information, waste of processing time and possibly circular dependencies:

  • first occurrence of the child will be processed and shown with all sub-children
  • already processed children will be filtered by default
  • the parameter "-a" will show a link to the first processed item (do not filter the line completely)
  • the parameter "-f" forces to process and show each child with all sub-children (stopped at the given depth level)

The option "-f" can lead to hang due to circular dependencies or great amount of work. If this setting is really needed and you note a very long delay, try to set the depth parameter "-d" as minimal as possible.

About

show golang dependence like tree

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.1%
  • Makefile 0.9%