From 0d2dbc86b861b69f017a7a292be966b7df8733c4 Mon Sep 17 00:00:00 2001 From: Lucas Bremgartner Date: Wed, 2 Sep 2020 13:59:47 +0200 Subject: [PATCH] Print version with -version flag --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index d6a5c8e..9dc4b6d 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ import ( ) // version is the command version, injected at build time. -var version string +var version string = "dev" type userFlags struct { outFile string @@ -31,6 +31,7 @@ func main() { flag.StringVar(&flags.formatter, "fmt", "", "go pretty-printer: gofmt, goimports or noop (default gofmt)") flag.BoolVar(&flags.stubImpl, "stub", false, "return zero values when no mock implementation is provided, do not panic") + printVersion := flag.Bool("version", false, "version for moq") flag.Usage = func() { fmt.Println(`moq [flags] source-dir interface [interface2 [interface3 [...]]]`) @@ -42,6 +43,11 @@ func main() { flag.Parse() flags.args = flag.Args() + if *printVersion { + fmt.Printf("moq version %s\n", version) + os.Exit(0) + } + if err := run(flags); err != nil { fmt.Fprintln(os.Stderr, err) flag.Usage()