-
Notifications
You must be signed in to change notification settings - Fork 142
Support invocation of mockgen via go tool with new write generate directive #246
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
base: main
Are you sure you want to change the base?
Conversation
The new -write_tool_generate_directive works the same way as the -write_generate_directive flag, except that it correctly regenerates "go tool mockgen" invocations of the mockgen tool.
WalkthroughThe update introduces a new command-line flag Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant GenerateMethod
User->>CLI: Run mockgen with flags
CLI->>GenerateMethod: Invoke Generate(flag settings)
alt Both flags are set
GenerateMethod->>User: Return error for mutually exclusive flags
else Flag writeToolGenerateDirective is set
GenerateMethod->>GenerateMethod: Format output using tool directive
else Flag writeGenerateDirective is set
GenerateMethod->>GenerateMethod: Format output using generate directive
end
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
The CLA tool doesn't seem to load for me.. 😕 edit: came back the next day and it was back up |
What?
This change adds a new flag:
-write_tool_generate_directive
, which correctly handles invocation ofmockgen
viago tool
in//go:generate
directives.Why?
The problem this fixes is using
go tool mockgen
to invokemockgen
in a//go:generate
directive.For example if I have a mock file with a
//go:generate
directive like this://go:generate go tool mockgen -destination ./mock_handler_test.go -write_generate_directive ...
Then it will be regenerated something like this:
//go:generate /home/scott/.cache/go-build/2b/2bdd48bc50b1532a85e833a029839a9b1e94233556b3072b236f31813080f176-d/mockgen -destination ./mock_handler_test.go -write_generate_directive ...
The new
-write_tool_generate_directive
flag introduced in this PR works the same way as the-write_generate_directive
flag, except that it correctly regenerates "go tool mockgen" invocations of the mockgen tool. So this will now be correctly regenerated://go:generate go tool mockgen -destination ./mock_handler_test.go -write_tool_generate_directive ...
Alternatives considered
It would be nice to detect when
mockgen
is being invoked bygo tool
instead of being executed directly, because then you could addgo tool mockgen
support directly to the existing-write_generate_directive
. But I couldn't find any simple way to detect when the tool is being called viago tool mockgen
.Summary by CodeRabbit