Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 1.09 KB

README.md

File metadata and controls

32 lines (22 loc) · 1.09 KB

GenClean

genclean is a utility to address a few shortcomings in mockgen (and other code-gen tools). Specifically:

  • Remove self referential imports;
  • Offers determinism when import aliasing;
  • Grouping imports into chunks based on prefixes;

Installation

go get -u github.com/m3db/build-tools/utilities/genclean

Usage

The following command orders the imports into three chunks: stdlib, those starting with "github.com/some", and third-party; and aliases them deterministically; and removes any imports from the same package.

mockgen -package=abc github.com/some/path/abc IFace0 \
 | genclean -cleanup-selfref -cleanup-import -prefixes "github.com/some" -pkg github.com/some/path/abc -out $GOPATH/src/github.com/some/path/abc/abc_mock.go

You can embed this inside a go:generate command, as follows:

//go:generate sh -c "mockgen -package=abc github.com/some/path/abc IFace0 | genclean ..."

Known Limitations

  • genclean assumes all go files in a folder $GOPATH/src/github.com/xyz/abc have package name set to the name of the folder ("abc" in this case).