From c6746947fb05d4be284c2423d5c38149c9d79fb5 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Thu, 10 May 2018 18:25:23 +0200 Subject: [PATCH] protoc-gen-go: Add -version flag to print version --- protoc-gen-go/main.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/protoc-gen-go/main.go b/protoc-gen-go/main.go index 8e2486de0b..e09d4d9f38 100644 --- a/protoc-gen-go/main.go +++ b/protoc-gen-go/main.go @@ -49,6 +49,7 @@ package main import ( + "flag" "io/ioutil" "os" @@ -56,7 +57,20 @@ import ( "github.com/golang/protobuf/protoc-gen-go/generator" ) +const ( + // versionString holds the current version of protoc-gen-go. + versionString = "1.1.0" +) + func main() { + // If the -version flag is set, just print the version and exit. + versionFlag := flag.Bool("version", false, "print the version of protoc-gen-go") + flag.Parse() + if *versionFlag { + os.Stdout.WriteString(versionString) + os.Exit(0) + } + // Begin by allocating a generator. The request and response structures are stored there // so we can do error handling easily - the response structure contains the field to // report failure.