diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index df7d85f..1f56802 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -61,6 +61,7 @@ var ( 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.") writePkgComment = flag.Bool("write_package_comment", true, "Writes package documentation comment (godoc) if true.") writeSourceComment = flag.Bool("write_source_comment", true, "Writes original file (source mode) or interface names (reflect mode) comment if true.") + writeInvocationComment = flag.Bool("write_invocation_comment", true, "Writes the specific command invocation used to generate this file into the comment header if true.") writeGenerateDirective = flag.Bool("write_generate_directive", false, "Add //go:generate directive to regenerate the mock") copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header") typed = flag.Bool("typed", false, "Generate Type-safe 'Return', 'Do', 'DoAndReturn' function") @@ -313,16 +314,18 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac g.p("// Source: %v (interfaces: %v)", g.srcPackage, g.srcInterfaces) } } - g.p("//") - g.p("// Generated by this command:") - g.p("//") - // only log the name of the executable, not the full path - name := filepath.Base(os.Args[0]) - if runtime.GOOS == "windows" { - name = strings.TrimSuffix(name, ".exe") + if *writeInvocationComment { + g.p("//") + g.p("// Generated by this command:") + g.p("//") + // only log the name of the executable, not the full path + name := filepath.Base(os.Args[0]) + if runtime.GOOS == "windows" { + name = strings.TrimSuffix(name, ".exe") + } + g.p("//\t%v", strings.Join(append([]string{name}, os.Args[1:]...), " ")) + g.p("//") } - g.p("//\t%v", strings.Join(append([]string{name}, os.Args[1:]...), " ")) - g.p("//") // Get all required imports, and generate unique names for them all. im := pkg.Imports()