godepg
generates a dependency graph for a go or php project using graphviz
. A dependency graph generated by godepg
using a config looks like the following:
Currently, the following technologies are supported:
- go
- php (composer)
- php (psr4)
In order to generate graphs you have to install graphviz
go get github.com/windler/godepg
Make sure that your $GOROOT
is set and is present in your path
export PATH=$PATH:$GOROOT/bin
For each language there is a subcommand. Type godepg <language> -h
to see a list of available options.
godepg go -h
OPTIONS:
-o file, --output file destination file to write png to
-p package, --package package the package to analyze
-n, --no-go-packages hide gos buildin packages
-d value, --depth value limit the depth of the graph (default: -1)
-f value, --filter value filter package name
-m, --my-packages-only show only subpackages of scanned package
-i package, --info package shows the dependencies for a package
--inverse shows all packages that depend on the package rather than its dependencies
--format value formats the dependencies output (--info)
godepg php-composer -h
OPTIONS:
-o file, --output file destination file to write png to
-p project, --project project the project to analyze
-f value, --filter value filter project name
-s value, --stop-at value dont scan dependencies of package name (pattern)
-d value, --depth value limit the depth of the graph (default: -1)
godepg php-psr4 -h
OPTIONS:
-o file destination file to write png to
-p project the project to analyze
-f value filter project name
-s value dont scan dependencies of package name (pattern)
-d value limit the depth of the graph (default: -1)
-e value exclude folder
All graphs are written to ~/godepg/<pkg>_timestamp.png
if option -o
is not present. You can change the home directory by setting the env GODEPG_HOME
.
When no language subcommand is specified, godepg
will try to read a config file named godepg.yml
to generate a dependy graph. You can also specify the config file with the option --file
. Following, there is a sample config file:
language: php-composer
output: /home/windler/projects/sample/deps.png
stopat:
- laravel
filter:
- php
- tinker
depth: 3
If you are using a config file you can also apply any dot attributes to style your graph. Example:
language: php-composer
output: /home/windler/projects/sample/deps.png
filter:
- php
depth: 3
edgestylepattern:
"":
arrowhead: open
color: white
fontcolor: white
splines: curved
sample:
arrowhead: vee
fontname: Courier
style: dashed
nodestyle:
fillcolor: "#336699"
style: filled
fontcolor: white
fontname: Courier
shape: rectangle
graphstyle:
bgcolor: "#333333"
After creating a config file, you can always update your current dependy graph using
cd /home/windler/projects/sample
godepg
or
godepg --file /home/windler/projects/sample/godepg.yml
Attribute | Type | Language | Description |
---|---|---|---|
language | string | all | the language to use |
filter | array | all | filters node names (hide) |
depth | int | all | max depth of the graph |
output | string | all | output file of the png (and dot file) |
edgestylepattern | map string -> (map string -> string) | all | apply dot attributes to edges. The first map key is a pattern on which nodes the attributes should be applied. If all nodes should be applied use "" . |
edgestyle | map string -> string | all | apply edge attributes |
nodestyle | map string -> string | all | apply node attributes |
graphstyle | map string -> string | all | apply graph attributes |
project | string | php | the project the use (relative to wd) |
exclude | array | php | folders to ignore |
stopat | array | php | print node but dont scan/print dependencies |
package | string | go | package name to scan |
nogopackages | bool | go | hide go packges in graph |
mypackagesonly | bool | go | only show subpackages of the scanned package |
Following, you can find sample outputs.
Samples for the ws package package.
godepg go -p github.com/windler/ws -o ~/ws_package.png -n
or
cd /user/windler/go/src/github.com/windler/ws
godepg go -p . -o ~/ws_package.png -n
godepg go -p github.com/windler/ws -m
godepg go -p github.com/windler/ws -n -f=ui -f=/git
Samples for a fresh Laravel installation called sample
.
godepg php-composer -p /home/windler/projects/sample -s=laravel
godepg php-composer -p /home/windler/projects/sample -f=symfony
You can also just print information about the dependencies of a package by using option -i
:
godepg go -p github.com/windler/ws -i github.com/windler/ws/app/config
There are 7 dependencies for package github.com/windler/ws/app/config:
0: github.com/windler/ws/app/commands
1: gopkg.in/yaml.v2
2: io/ioutil
3: log
4: os
5: os/user
6: strings
If you would like to see a list of packages that depend on a specific package, just add the --inverse
option:
godepg go -p github.com/windler/ws -i github.com/windler/ws/app/config --inverse
There are 1 dependents for package github.com/windler/ws/app/config:
0: github.com/windler/ws
You can modify the output by passing a template
using --format
:
godepg go -p github.com/windler/ws -i github.com/windler/ws --format "Deps: {{.Count}}"
Deps: 5
You can use the following fields:
Field | Description |
---|---|
Package | The name of the scanned package |
Count | Number of found dependencies |
Dependencies | Array of packages |
DependencyType | Type of the dependencies (dependency or dependent) |