From f1b996eea06f3f38480e440c461def59d75bed0f Mon Sep 17 00:00:00 2001 From: Ulderico Cirello Date: Fri, 29 Mar 2024 13:08:34 -0700 Subject: [PATCH] moq: add flag to toggle GODEBUG=gotypealias=1 --- internal/typealias/typealias_older.go | 3 ++- main.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/typealias/typealias_older.go b/internal/typealias/typealias_older.go index 534072c..bb0760a 100644 --- a/internal/typealias/typealias_older.go +++ b/internal/typealias/typealias_older.go @@ -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) } diff --git a/main.go b/main.go index e46d276..1dbbd48 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,6 @@ import ( ) func main() { - typealias.ConfigureGoDebug() log.SetPrefix("moq: ") log.SetFlags(0) debugFlags := strings.Split(",", strings.ToLower(os.Getenv("MOQ_DEBUG"))) @@ -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") @@ -47,6 +47,10 @@ func main() { log.Fatal("cannot parse flags") } + if *typeAlias { + typealias.ConfigureGoDebug() + } + if *printVersion { info, ok := debug.ReadBuildInfo() if !ok {