Skip to content

Commit 2c718f2

Browse files
authored
Add --write_command_comment=false option (#153)
The invocation command can be user specific, especially if absolute paths are used for the destination. This in turn can cause very large needless diffs that will create lots of source control noise and be distracting in PRs. To remove these command comments simply pass `--write_command_comment=false` on the CLI. The default behavior is maintained. Fixes #104.
1 parent 39ddc38 commit 2c718f2

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

mockgen/mockgen.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ var (
5959
mockNames = flag.String("mock_names", "", "Comma-separated interfaceName=mockName pairs of explicit mock names to use. Mock names default to 'Mock'+ interfaceName suffix.")
6060
packageOut = flag.String("package", "", "Package of the generated code; defaults to the package of the input with a 'mock_' prefix.")
6161
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+
writeCmdComment = flag.Bool("write_command_comment", true, "Writes the command used as a comment if true.")
6263
writePkgComment = flag.Bool("write_package_comment", true, "Writes package documentation comment (godoc) if true.")
6364
writeSourceComment = flag.Bool("write_source_comment", true, "Writes original file (source mode) or interface names (reflect mode) comment if true.")
6465
writeGenerateDirective = flag.Bool("write_generate_directive", false, "Add //go:generate directive to regenerate the mock")
@@ -313,16 +314,18 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac
313314
g.p("// Source: %v (interfaces: %v)", g.srcPackage, g.srcInterfaces)
314315
}
315316
}
316-
g.p("//")
317-
g.p("// Generated by this command:")
318-
g.p("//")
319-
// only log the name of the executable, not the full path
320-
name := filepath.Base(os.Args[0])
321-
if runtime.GOOS == "windows" {
322-
name = strings.TrimSuffix(name, ".exe")
317+
if *writeCmdComment {
318+
g.p("//")
319+
g.p("// Generated by this command:")
320+
g.p("//")
321+
// only log the name of the executable, not the full path
322+
name := filepath.Base(os.Args[0])
323+
if runtime.GOOS == "windows" {
324+
name = strings.TrimSuffix(name, ".exe")
325+
}
326+
g.p("//\t%v", strings.Join(append([]string{name}, os.Args[1:]...), " "))
327+
g.p("//")
323328
}
324-
g.p("//\t%v", strings.Join(append([]string{name}, os.Args[1:]...), " "))
325-
g.p("//")
326329

327330
// Get all required imports, and generate unique names for them all.
328331
im := pkg.Imports()

0 commit comments

Comments
 (0)