Browse Source

Add "--version" to protoc-gen-grpc-swift (#1557)

Motivation:

It can be useful to know the version of the protoc plugin being used.

Modifications:

- Add a "--version" flag to protoc-gen-grpc-swift which prints the
  plugin name and version.

Result:

Resolves #1556
George Barnett 3 years ago
parent
commit
250c768ac6

+ 1 - 0
Sources/protoc-gen-grpc-swift/Version.swift

@@ -0,0 +1 @@
+../GRPC/Version.swift

+ 13 - 2
Sources/protoc-gen-grpc-swift/main.swift

@@ -104,7 +104,18 @@ func uniqueOutputFileName(
   }
   }
 }
 }
 
 
-func main() throws {
+func printVersion(args: [String]) {
+  // Stip off the file path
+  let program = args.first?.split(separator: "/").last ?? "protoc-gen-grpc-swift"
+  print("\(program) \(Version.versionString)")
+}
+
+func main(args: [String]) throws {
+  if args.dropFirst().contains("--version") {
+    printVersion(args: args)
+    return
+  }
+
   // initialize responses
   // initialize responses
   var response = Google_Protobuf_Compiler_CodeGeneratorResponse(
   var response = Google_Protobuf_Compiler_CodeGeneratorResponse(
     files: [],
     files: [],
@@ -147,7 +158,7 @@ func main() throws {
 }
 }
 
 
 do {
 do {
-  try main()
+  try main(args: CommandLine.arguments)
 } catch {
 } catch {
   Log("ERROR: \(error)")
   Log("ERROR: \(error)")
 }
 }