-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support overriding destination package name and type naming template in "-generate" call #191
Comments
@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. |
When the -generate flag is given with a -o flag, that flag will be the default value for each invocation. If the invocation specifies it's own -o, then that value will be used. Similar logic applies for the -header flag (which was true before this commit) and for the -q flag. Also, there is now a -fake-name-template flag when -generate is provided. When an invocation does not specify a -fake-name, the value in -fake-name-template will be evaluated as a text/template string and then run against an object with a `TargetName` field. The result will be the -fake-name for the invocation. For example, the following comments will result in a fake named `TheMaskedSinger` in the `fakes` package: //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate -o fakes -fake-name-template "TheMasked{{.TargetName}}" //counterfeiter:generate . Singer [Issue maxbrunsfeld#191] Authored-by: Matt Royal <[email protected]>
When the -generate flag is given with a -o flag, that flag will be the default value for each invocation. If the invocation specifies it's own -o, then that value will be used. Similar logic applies for the -header flag (which was true before this commit) and for the -q flag. Also, there is now a -fake-name-template flag when -generate is provided. When an invocation does not specify a -fake-name, the value in -fake-name-template will be evaluated as a text/template string and then run against an object with a `TargetName` field. The result will be the -fake-name for the invocation. For example, the following comments will result in a fake named `TheMaskedSinger` in the `fakes` package: //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate -o fakes -fake-name-template "TheMasked{{.TargetName}}" //counterfeiter:generate . Singer [Issue maxbrunsfeld#191] Authored-by: Matt Royal <[email protected]>
I took a crack at this in #195. Please let me know what you think |
When the -generate flag is given with a -o flag, that flag will be the default value for each invocation. If the invocation specifies it's own -o, then that value will be used. Similar logic applies for the -header flag (which was true before this commit) and for the -q flag. Also, there is now a -fake-name-template flag when -generate is provided. When an invocation does not specify a -fake-name, the value in -fake-name-template will be evaluated as a text/template string and then run against an object with a `TargetName` field. The result will be the -fake-name for the invocation. For example, the following comments will result in a fake named `TheMaskedSinger` in the `fakes` package: //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate -o fakes -fake-name-template "TheMasked{{.TargetName}}" //counterfeiter:generate . Singer [Issue maxbrunsfeld#191] Authored-by: Matt Royal <[email protected]>
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:
This allows me to refer to the fake like this:
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: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!
The text was updated successfully, but these errors were encountered: