godependants

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

godependants

List dependant packages.

Sometimes you have a large, sprawling codebase, and you desperately would like to know exactly which packages import (or depend on) the current package. Enter godependants.

Suppose you have three packages in your Go module, and the dependency graph looks like this:

foo -> bar -> baz

where foo imports bar, and bar imports baz. To know all of the packages that directly and indirectly depend on baz, you can run:

$ godependants github.com/nesv/godependants/baz
github.com/nesv/godependants/bar
github.com/nesv/godependants/foo

Note that the output of godependants is not deterministic, nor is it sorted.

Direct dependencies

If you would like to only show direct dependants, specify the -direct flag:

$ godependants -direct github.com/nesv/godependants/baz
github.com/nesv/godependants/bar

Shhhh...

godependants can be a little noisy. It prints diagnostic information to STDERR. To prevent it from doing this, pass the -quiet flag.

$ godependants -quiet ...

Continuous integration

Where godependants can shine, is in continuous integration and testing environments!

Suppose you have a very, very large repository, and would only like to run tests on the packages that would have been affected by a recent change. Your first step would be to get the list of all packages that have changed:

pkgs_changed=$(git diff --name-only --diff-filter=ACM |\
  grep -E '\.go$' |\
  xargs dirname |\
  uniq)

Next, take that list, and pass it to godependants:

godependants ${pkgs_changed[*]}

Then you can take the resulting list, and pass it to go test.

For a really gnarly one-liner:

git diff --name-only --diff-filter=ACM |\
  grep -E '\.go$' |\
  xargs dirname |\
  sort |\
  uniq |\
  xargs godependants |\
  go test

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL