Skip to content

Commit

Permalink
Implement protoc-gen-rbs
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Jul 9, 2020
1 parent d7d5470 commit 0fcd6a7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion exe/protoc-gen-rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ $LOAD_PATH << File.join(__dir__, "../lib")

require "rbs_protobuf"

backend = ENV["RBS_PROTOBUF_BACKEND"]
unless backend
STDERR.puts "🚨🚨🚨 protoc-gen-rbs requires RBS_PROTOBUF_BACKEND environment variable. 🚨🚨🚨"
STDERR.puts " Possible options:"
STDERR.puts " RBS_PROTOBUF_BACKEND=protobuf (for protobuf gem)"
STDERR.puts " RBS_PROTOBUF_BACKEND=google-protobuf (for google-protobuf gem)"
exit 1
end

input = Google::Protobuf::Compiler::CodeGeneratorRequest.decode(STDIN.read)
response = RBSProtobuf::Translator.new(input).response

translator = case backend
when "protobuf"
upcase_enum = ENV.key?("PB_UPCASE_ENUMS")

RBSProtobuf::Translator::ProtobufGem.new(
input,
upcase_enum: upcase_enum
)
when "google-protobuf"
raise NotImplementedError
end

response = translator.response
print Google::Protobuf::Compiler::CodeGeneratorResponse.encode(response)

0 comments on commit 0fcd6a7

Please sign in to comment.