golang/mock

mockgen: Use Go generate variables as default flag values

uhthomas opened this issue · 2 comments

Requested feature

The default flag values for mockgen are blank, it might be nice to use the variables from Go generate as the default.

Why the feature is needed

Go generate comments for mockgen always have to specify the -source and -destination attributes.

//go:generate -command mockgen go run github.com/golang/mock/mockgen
//go:generate mockgen -source=$GOFILE -destination=mock/some_interface_mock_test.go -package mock SomeInterface

This is quite verbose, and feels unnecessary.

(Optional) Proposed solution

What if -source and -destination were automatically inferred from the environment? Even nicer if the destination files were suffixed with _test by default as I can't imagine many people use mocks in non-test code.

//go:generate mockgen SomeInterface

Source might be able to be inferred for reflect mode when you have an interface to work off of, but I am not sure if it makes sense for source mode. I think the explicitness is nice as there are lots of patterns used by many people on where they generate their mocks. Some do it into the same package they are in, some in a test package, and others move all of their mocks into a subpackage. Because of this complexity I think the verbosity is justified in this case. WDYT?

Closing due to lack of response.