Skip to content

Commit

Permalink
Add --outpkg argument
Browse files Browse the repository at this point in the history
Set --outpkg=foo to change the generated package name from "mocks" to "foo". No
new tests, but I verified that this change works locally, both with and without
the flag.
  • Loading branch information
kevinburke committed Jul 22, 2016
1 parent 29089e3 commit e6439f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions cmd/mockery/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
fName string
fPrint bool
fOutput string
fOutpkg string
fDir string
fRecursive bool
fAll bool
Expand Down Expand Up @@ -68,9 +69,10 @@ func main() {
}

visitor := &mockery.GeneratorVisitor{
InPackage: config.fIP,
Note: config.fNote,
Osp: osp,
InPackage: config.fIP,
Note: config.fNote,
Osp: osp,
PackageName: config.fOutpkg,
}

walker := mockery.Walker{
Expand All @@ -95,6 +97,7 @@ func parseConfigFromArgs(args []string) Config {
flagSet.StringVar(&config.fName, "name", "", "name or matching regular expression of interface to generate mock for")
flagSet.BoolVar(&config.fPrint, "print", false, "print the generated mock to stdout")
flagSet.StringVar(&config.fOutput, "output", "./mocks", "directory to write mocks to")
flagSet.StringVar(&config.fOutpkg, "outpkg", "mocks", "name of generated package")
flagSet.StringVar(&config.fDir, "dir", ".", "directory to search for interfaces")
flagSet.BoolVar(&config.fRecursive, "recursive", false, "recurse search into sub-directories")
flagSet.BoolVar(&config.fAll, "all", false, "generates mocks for all found interfaces in all sub-directories")
Expand Down
4 changes: 3 additions & 1 deletion mockery/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ type GeneratorVisitor struct {
InPackage bool
Note string
Osp OutputStreamProvider
// The name of the output package, if InPackage is false (defaults to "mocks")
PackageName string
}

func (this *GeneratorVisitor) VisitWalk(iface *Interface) error {
Expand All @@ -98,7 +100,7 @@ func (this *GeneratorVisitor) VisitWalk(iface *Interface) error {
if this.InPackage {
pkg = iface.File.Name.String()
} else {
pkg = "mocks"
pkg = this.PackageName
}

out, err, closer := this.Osp.GetWriter(iface, pkg)
Expand Down

0 comments on commit e6439f8

Please sign in to comment.