Add -stub flag to stub func implementation (#132)
When a mock is generated with the flag enabled, it introduces the following changes: - Does not panic on calling the method without a mock implementation. - Return zero values iff the implementation is not provided and the method has return parameters. Co-authored-by: Scott Leuthaeuser <scott_leuthaeuser@homedepot.com>
This commit is contained in:
4
main.go
4
main.go
@@ -17,6 +17,7 @@ type userFlags struct {
|
||||
outFile string
|
||||
pkgName string
|
||||
formatter string
|
||||
stubImpl bool
|
||||
args []string
|
||||
}
|
||||
|
||||
@@ -25,6 +26,8 @@ func main() {
|
||||
flag.StringVar(&flags.outFile, "out", "", "output file (default stdout)")
|
||||
flag.StringVar(&flags.pkgName, "pkg", "", "package name (default will infer)")
|
||||
flag.StringVar(&flags.formatter, "fmt", "", "go pretty-printer: gofmt (default) or goimports")
|
||||
flag.BoolVar(&flags.stubImpl, "stubImpl", false,
|
||||
"return zero values when no mock implementation is provided, do not panic")
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Println(`moq [flags] source-dir interface [interface2 [interface3 [...]]]`)
|
||||
@@ -59,6 +62,7 @@ func run(flags userFlags) error {
|
||||
SrcDir: srcDir,
|
||||
PkgName: flags.pkgName,
|
||||
Formatter: flags.formatter,
|
||||
StubImpl: flags.stubImpl,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user