Support overriding destination package name and type naming template in "-generate" call
matt-royal opened this issue · 5 comments
I've found that I prefer to use a package called "fake" for my fakes, and that I prefer to remove "Fake" from the type name. This looks like the following currently:
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
//counterfeiter:generate -o fake -fake-name MyRepository . MyRepository
//counterfeiter:generate -o fake -fake-name MyPresenter . MyPresenter
This allows me to refer to the fake like this:
myRepository := new(fake.MyRepository)
Unfortunately, I have to repeat those -o
and -fake-name
arguments in every generate call. It would be nice to be able to do something like the following:
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate -o fake -fake-name-template "{{.TargetName}}"
//counterfeiter:generate . MyRepository
//counterfeiter:generate . MyPresenter
I'm happy to work on a PR to add this behavior, but I want to make sure you'd be open to the idea first. I'd also love to hear other ideas to accomplish the same goal of removing repetition and risk of inconsistency.
Thanks!
@maxbrunsfeld, @joefitzgerald, and @tjarratt Any thoughts on this? It seems like y'all are the maintainers these days
Hey Matt! This makes a lot of sense to me, from my understanding.
I would merge such a PR, although @joefitzgerald is now the primary author and maintainer of this project - it’s been basically rewritten (and much improved) since I last touched it.
This sounds like a great idea! +1 to merging a PR like this. Thanks so much for your help @matt-royal 🙏 .
Thank you, @maxbrunsfeld and @joefitzgerald for all your work writing and maintaining counterfeiter. I can't imagine testing in go without it.
I'm not sure how soon I'll have the PR ready but I'll send it your way when it's done.
I took a crack at this in #195. Please let me know what you think