You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Requested feature
The ability to invoke mockgen in reflect mode with relative import paths.
For context, users currently do the following for reflect mode:
mockgen [bunch of flags] github.com/myorg/myproject/foo/bar Iface1,Iface2
With go generate, this might take the form:
// In foo/bar/gen.go
//go:generate mockgen [bunch of flags] github.com/myorg/myproject/foo/bar Iface1,Iface2
The proposal suggests making the following possible:
// In foo/bar/gen.go
//go:generate mockgen [bunch of flags flags] . Iface1,Iface2
// In foo/gen.go
//go:generate mockgen [bunch of flags flags] ./bar Iface1,Iface2
Why the feature is needed
It's not uncommon to place gen.go files in your project source to generate helper mocks as subpackages or the like.
Not being able to use relative paths here results in extremely long, largely-unreadable go:generate lines.
(Optional) Proposed solution
There's currently logic in place that attempts to determine the import path of the current package if the requested import path is ".". In module mode, it looks for a go.mod file and extracts it from there.
I think this might be possible by making that logic a bit smarter and allowing it to handle other relative paths.
The tool will need to disambiguate between "mockgen foo/bar" meaning "relative directory foo/bar" or "import path foo/bar". This could be with a simple enforcement mechanism: relative directory foo/bar must be prefixed with "./".
The text was updated successfully, but these errors were encountered:
Requested feature
The ability to invoke
mockgen
in reflect mode with relative import paths.For context, users currently do the following for reflect mode:
With
go generate
, this might take the form:The proposal suggests making the following possible:
(The first form seems already supported in the source code.)
Why the feature is needed
It's not uncommon to place gen.go files in your project source to generate helper mocks as subpackages or the like.
Not being able to use relative paths here results in extremely long, largely-unreadable go:generate lines.
(Optional) Proposed solution
There's currently logic in place that attempts to determine the import path of the current package if the requested import path is ".". In module mode, it looks for a go.mod file and extracts it from there.
I think this might be possible by making that logic a bit smarter and allowing it to handle other relative paths.
The tool will need to disambiguate between "mockgen foo/bar" meaning "relative directory foo/bar" or "import path foo/bar". This could be with a simple enforcement mechanism: relative directory foo/bar must be prefixed with "./".
The text was updated successfully, but these errors were encountered: