Skip to content
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

generate mode accepts -o, -fake-name-template & -q #195

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

matt-royal
Copy link

This PR implements the feature discussed in #191. I did my best to add the feature without making invasive changes, but I did have to restructure how flags are parsed. I'm definitely open to feedback on how I can improve the commit or the feature itself. Here are some specific questions I have:

  • Is -fake-name-template a good name for the flag?
  • Is text/template the right approach here, or would a simple regex, or a prefix + suffix flag be better?
  • If text/template works here, is TargetName alright as the field available in the template, or would another name be better. Perhaps just Name?

/cc @joefitzgerald @maxbrunsfeld

@joefitzgerald
Copy link
Collaborator

Thanks for the PR @matt-royal 🙏 I will review this weekend!

@joefitzgerald joefitzgerald force-pushed the pr/generate-accepts-defaults branch from e1ec564 to 608c488 Compare January 22, 2022 23:37
matt-royal and others added 2 commits January 24, 2022 07:41
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants