Skip to content

Commit 9dfb7d6

Browse files
authored
Merge pull request #128 from zcolleen/master
Prefix
2 parents bda9c15 + 74456d5 commit 9dfb7d6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ or install minimock using [v2 branch](https://github.com/gojuno/minimock/tree/v2
5050
-p string
5151
comma-separated package names,
5252
by default the generated package names are taken from the destination directory names
53+
-pr string
54+
mock file prefix
5355
-s string
5456
mock file suffix (default "_mock_test.go")
5557
-gr

cmd/minimock/minimock.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type (
5454
interfaces []interfaceInfo
5555
noGenerate bool
5656
suffix string
57+
prefix string
5758
mockNames []string
5859
packageNames []string
5960
goGenerateGoRun bool
@@ -173,15 +174,15 @@ func run(opts *options) (err error) {
173174
if len(opts.interfaces) == len(opts.mockNames) {
174175
mockName = opts.mockNames[i]
175176
}
176-
if err := processPackage(gopts, interfaces, in.WriteTo, opts.suffix, mockName); err != nil {
177+
if err := processPackage(gopts, interfaces, in.WriteTo, opts.prefix, opts.suffix, mockName); err != nil {
177178
return err
178179
}
179180
}
180181

181182
return nil
182183
}
183184

184-
func processPackage(opts generator.Options, interfaces []types.InterfaceSpecification, writeTo, suffix, mockName string) (err error) {
185+
func processPackage(opts generator.Options, interfaces []types.InterfaceSpecification, writeTo, prefix, suffix, mockName string) (err error) {
185186
for _, iface := range interfaces {
186187
opts.InterfaceName = iface.InterfaceName
187188

@@ -201,7 +202,7 @@ func processPackage(opts generator.Options, interfaces []types.InterfaceSpecific
201202

202203
paramsString := strings.Join(params, ",")
203204

204-
opts.OutputFile, err = destinationFile(iface.InterfaceName, writeTo, suffix)
205+
opts.OutputFile, err = destinationFile(iface.InterfaceName, writeTo, prefix, suffix)
205206
if err != nil {
206207
return errors.Wrapf(err, "failed to generate mock for %s", iface.InterfaceName)
207208
}
@@ -268,7 +269,7 @@ func isGoFile(path string) (bool, error) {
268269
return strings.HasSuffix(path, ".go") && !stat.IsDir(), nil
269270
}
270271

271-
func destinationFile(interfaceName, writeTo, suffix string) (string, error) {
272+
func destinationFile(interfaceName, writeTo, prefix, suffix string) (string, error) {
272273
ok, err := isGoFile(writeTo)
273274
if err != nil {
274275
return "", err
@@ -279,7 +280,7 @@ func destinationFile(interfaceName, writeTo, suffix string) (string, error) {
279280
if ok {
280281
path = writeTo
281282
} else {
282-
path = filepath.Join(writeTo, minimock.CamelToSnake(interfaceName)+suffix)
283+
path = filepath.Join(writeTo, prefix+minimock.CamelToSnake(interfaceName)+suffix)
283284
}
284285

285286
if !strings.HasPrefix(path, "/") && !strings.HasPrefix(path, ".") {
@@ -387,7 +388,7 @@ func processArgs(args []string, stdout, stderr io.Writer) (*options, error) {
387388
fs.BoolVar(&opts.goGenerateGoRun, "gr", false, `changes go:generate line from "//go:generate minimock args..." to "//go:generate go run github.com/gojuno/minimock/v3/cmd/minimock",
388389
useful while controlling minimock version with go mod`)
389390
fs.StringVar(&opts.suffix, "s", "_mock_test.go", "mock file suffix")
390-
391+
fs.StringVar(&opts.prefix, "pr", "", "mock file prefix")
391392
input := fs.String("i", "*", "comma-separated names of the interfaces to mock, i.e fmt.Stringer,io.Reader\nuse io.* notation to generate mocks for all interfaces in the \"io\" package")
392393
output := fs.String("o", "", "comma-separated destination file names or packages to put the generated mocks in,\nby default the generated mock is placed in the source package directory")
393394
aliases := fs.String("n", "", "comma-separated mock names,\nby default the generated mock names append `Mock` to the given interface name")

0 commit comments

Comments
 (0)