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

Command line flag to toggle whether to emit source file/interface names comment in generated code #32

Closed
utgwkk opened this issue Jul 11, 2023 · 1 comment · Fixed by #33
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@utgwkk
Copy link
Contributor

utgwkk commented Jul 11, 2023

Requested feature
I want to toggle whether to emit a comment of mock's origin (a .go file for source mode, a package and interface names for reflect mode) in a generated code like below (from example code):

// Source: go.uber.org/mock/sample (interfaces: Index,Embed,Embedded)

Why the feature is needed
I made a wrapper tool of mockgen (named bulkmockgen), which manages interfaces to be mocked with a variable in a .go file and invokes mockgen with symbols arguments from the variable.

For example, running go generate with the below code will execute a command mockgen -package mock_foo -destination ./mock_foo/mock.go . IFoo,IBar.

//go:generate bulkmockgen Iset -- -package mock_foo -destination ./mock_foo/mock.go
var Iset = []any{
	new(IFoo),
	new(IBar),
}

This works fine, but there is a problem that the generated code's comment causes many Git conflicts because there are original interface names in one line in a top of generated code and the line is edited every time I add an interface name to mock target list.

(Optional) Proposed solution
Adding a command line flag like -write_source_comment and controlling whether to emit mock's origin comment by the flag will solve the problem described above.
I implemented it in my repository fork.

@sywhang
Copy link
Contributor

sywhang commented Jul 11, 2023

Thanks, this is a reasonable request, given how we already have write_package_comment.

If you want to make a pull request for this, we'll review it soon.

@sywhang sywhang added enhancement New feature or request good first issue Good for newcomers labels Jul 11, 2023
sywhang pushed a commit that referenced this issue Jul 11, 2023
ErfanMomeniii pushed a commit to ErfanMomeniii/mock that referenced this issue Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
2 participants