Skip to content

Commit 93882cc

Browse files
authored
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
1 parent bcca31f commit 93882cc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../GRPC/Version.swift

Sources/protoc-gen-grpc-swift/main.swift

+13-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,18 @@ func uniqueOutputFileName(
104104
}
105105
}
106106

107-
func main() throws {
107+
func printVersion(args: [String]) {
108+
// Stip off the file path
109+
let program = args.first?.split(separator: "/").last ?? "protoc-gen-grpc-swift"
110+
print("\(program) \(Version.versionString)")
111+
}
112+
113+
func main(args: [String]) throws {
114+
if args.dropFirst().contains("--version") {
115+
printVersion(args: args)
116+
return
117+
}
118+
108119
// initialize responses
109120
var response = Google_Protobuf_Compiler_CodeGeneratorResponse(
110121
files: [],
@@ -147,7 +158,7 @@ func main() throws {
147158
}
148159

149160
do {
150-
try main()
161+
try main(args: CommandLine.arguments)
151162
} catch {
152163
Log("ERROR: \(error)")
153164
}

0 commit comments

Comments
 (0)