Skip to content

Commit

Permalink
Provide a flag to control generation of the invocation comment
Browse files Browse the repository at this point in the history
The invocation comment stores the complete details of all provided
arguments, which may include paths to files. These aren't always
consistent, which results in unwanted changes in the generated files
(especially for CI checking for unexpected changes...).

Since the invocation isn't always useful, provide a flag to control
whether the comment is generated. To preserve current behaviour this
defaults to true (enabled).

Signed-off-by: Stephen Kitt <[email protected]>
  • Loading branch information
skitt committed Oct 9, 2023
1 parent 7842e1d commit d7b8b5e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
packageOut = flag.String("package", "", "Package of the generated code; defaults to the package of the input with a 'mock_' prefix.")
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.")
writeInvocationComment = flag.Bool("write_invocation_comment", true, "Writes the invocation used to generate the file in a comment if true.")
writeSourceComment = flag.Bool("write_source_comment", true, "Writes original file (source mode) or interface names (reflect mode) comment 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")
Expand Down Expand Up @@ -312,10 +313,12 @@ 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:")
// only log the name of the executable, not the full path
g.p("// %v", strings.Join(append([]string{filepath.Base(os.Args[0])}, os.Args[1:]...), " "))
if *writeInvocationComment {
g.p("//")
g.p("// Generated by this command:")
// only log the name of the executable, not the full path
g.p("// %v", strings.Join(append([]string{filepath.Base(os.Args[0])}, os.Args[1:]...), " "))
}

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

0 comments on commit d7b8b5e

Please sign in to comment.