Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 03b6973

Browse files
authored
Add -write_source_comment flag to toggle whether to emit source file/interface names comment (#33)
Fix #32
1 parent 0181604 commit 03b6973

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ It supports the following flags:
113113

114114
- `-write_package_comment`: Writes package documentation comment (godoc) if true. (default true)
115115

116+
- `-write_source_comment`: Writes original file (source mode) or interface names (reflect mode) comment if true. (default true)
117+
116118
- `-typed`: Generate Type-safe 'Return', 'Do', 'DoAndReturn' function. (default false)
117119

118120
For an example of the use of `mockgen`, see the `sample/` directory. In simple

mockgen/mockgen.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ var (
5454
)
5555

5656
var (
57-
source = flag.String("source", "", "(source mode) Input Go source file; enables source mode.")
58-
destination = flag.String("destination", "", "Output file; defaults to stdout.")
59-
mockNames = flag.String("mock_names", "", "Comma-separated interfaceName=mockName pairs of explicit mock names to use. Mock names default to 'Mock'+ interfaceName suffix.")
60-
packageOut = flag.String("package", "", "Package of the generated code; defaults to the package of the input with a 'mock_' prefix.")
61-
selfPackage = flag.String("self_package", "", "The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude.")
62-
writePkgComment = flag.Bool("write_package_comment", true, "Writes package documentation comment (godoc) if true.")
63-
copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header")
64-
typed = flag.Bool("typed", false, "Generate Type-safe 'Return', 'Do', 'DoAndReturn' function")
57+
source = flag.String("source", "", "(source mode) Input Go source file; enables source mode.")
58+
destination = flag.String("destination", "", "Output file; defaults to stdout.")
59+
mockNames = flag.String("mock_names", "", "Comma-separated interfaceName=mockName pairs of explicit mock names to use. Mock names default to 'Mock'+ interfaceName suffix.")
60+
packageOut = flag.String("package", "", "Package of the generated code; defaults to the package of the input with a 'mock_' prefix.")
61+
selfPackage = flag.String("self_package", "", "The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude.")
62+
writePkgComment = flag.Bool("write_package_comment", true, "Writes package documentation comment (godoc) if true.")
63+
writeSourceComment = flag.Bool("write_source_comment", true, "Writes original file (source mode) or interface names (reflect mode) comment if true.")
64+
copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header")
65+
typed = flag.Bool("typed", false, "Generate Type-safe 'Return', 'Do', 'DoAndReturn' function")
6566

6667
debugParser = flag.Bool("debug_parser", false, "Print out parser results only.")
6768
showVersion = flag.Bool("version", false, "Print version.")
@@ -283,10 +284,12 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac
283284
}
284285

285286
g.p("// Code generated by MockGen. DO NOT EDIT.")
286-
if g.filename != "" {
287-
g.p("// Source: %v", g.filename)
288-
} else {
289-
g.p("// Source: %v (interfaces: %v)", g.srcPackage, g.srcInterfaces)
287+
if *writeSourceComment {
288+
if g.filename != "" {
289+
g.p("// Source: %v", g.filename)
290+
} else {
291+
g.p("// Source: %v (interfaces: %v)", g.srcPackage, g.srcInterfaces)
292+
}
290293
}
291294
g.p("")
292295

0 commit comments

Comments
 (0)