Skip to content

Commit

Permalink
moq: add flag to toggle GODEBUG=gotypealias=1
Browse files Browse the repository at this point in the history
  • Loading branch information
ucirello committed Mar 29, 2024
1 parent f43693b commit f1b996e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/typealias/typealias_older.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ import (
)

func ConfigureGoDebug() {
fmt.Fprintln(os.Stderr, "only partial generics and type alias support")
fmt.Fprintln(os.Stderr, "type alias inside generics support only available in Go 1.22+")
os.Exit(1)
}
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
)

func main() {
typealias.ConfigureGoDebug()
log.SetPrefix("moq: ")
log.SetFlags(0)
debugFlags := strings.Split(",", strings.ToLower(os.Getenv("MOQ_DEBUG")))
Expand All @@ -33,6 +32,7 @@ func main() {
flagset.BoolVar(&moqCfg.StubImpl, "stub", false, "return zero values when no mock implementation is provided, do not panic")
flagset.BoolVar(&moqCfg.SkipEnsure, "skip-ensure", false, "suppress check that confirms a mock implements an interface, avoid import cycle if mocks generated outside of the tested package")
remove := flagset.Bool("rm", false, "first remove output file, if it exists")
typeAlias := flagset.Bool("typealias", false, "enable type alias support inside generics. (gotypesalias=1)")
flagset.BoolVar(&moqCfg.WithResets, "with-resets", false, "generate functions to facilitate resetting calls made to a mock")
printVersion := flagset.Bool("version", false, "show the version for moq")

Expand All @@ -47,6 +47,10 @@ func main() {
log.Fatal("cannot parse flags")
}

if *typeAlias {
typealias.ConfigureGoDebug()
}

if *printVersion {
info, ok := debug.ReadBuildInfo()
if !ok {
Expand Down

0 comments on commit f1b996e

Please sign in to comment.