From cd1959ceee816774e20c81d7239af27306f5b76a Mon Sep 17 00:00:00 2001 From: Nilesh Singh Date: Sat, 12 Jun 2021 20:17:46 +0530 Subject: [PATCH 1/3] Add invocation args & mockgen version in generated code --- mockgen/mockgen.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index 50487070..53d997eb 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -31,6 +31,7 @@ import ( "os/exec" "path" "path/filepath" + "runtime/debug" "sort" "strconv" "strings" @@ -279,6 +280,16 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac } else { g.p("// Source: %v (interfaces: %v)", g.srcPackage, g.srcInterfaces) } + g.p("//") + + g.p("// Generated by this command:") + invocatedCmd := strings.Join(os.Args, " ") + g.p("// %v", invocatedCmd) + + if bi, exists := debug.ReadBuildInfo(); exists { + g.p("//") + g.p("// Mockgen version: %v", bi.Main.Version) + } g.p("") // Get all required imports, and generate unique names for them all. From 3c87ee3fd0ca84ac314de919606d3bf092774d57 Mon Sep 17 00:00:00 2001 From: Nilesh Singh Date: Sun, 1 Aug 2021 00:32:40 +0530 Subject: [PATCH 2/3] Fix mockgen version --- mockgen/mockgen.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index 53d997eb..bba25d42 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -286,8 +286,10 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac invocatedCmd := strings.Join(os.Args, " ") g.p("// %v", invocatedCmd) - if bi, exists := debug.ReadBuildInfo(); exists { - g.p("//") + g.p("//") + if version != "" { + g.p("// Mockgen version: %v", version) + } else if bi, exists := debug.ReadBuildInfo(); exists { g.p("// Mockgen version: %v", bi.Main.Version) } g.p("") From 66f68602f03681faa126c34ad080a24618bd6eb7 Mon Sep 17 00:00:00 2001 From: Nilesh Singh Date: Sun, 1 Aug 2021 00:43:22 +0530 Subject: [PATCH 3/3] Fix mockgen version --- mockgen/mockgen.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index bba25d42..0dc4acc4 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -283,14 +283,14 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac g.p("//") g.p("// Generated by this command:") - invocatedCmd := strings.Join(os.Args, " ") - g.p("// %v", invocatedCmd) + invokedArgs := strings.Join(os.Args, " ") + g.p("// %v", invokedArgs) g.p("//") if version != "" { - g.p("// Mockgen version: %v", version) + g.p("// Mockgen version: %s", version) } else if bi, exists := debug.ReadBuildInfo(); exists { - g.p("// Mockgen version: %v", bi.Main.Version) + g.p("// Mockgen version: %s", bi.Main.Version) } g.p("")