Created
May 8, 2023 08:44
-
-
Save slabuz/b66432d9c71dd100d193617754c79911 to your computer and use it in GitHub Desktop.
Prototype protobuf generator for scala-cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//> using scala "2.13" | |
//> using dep "com.thesamet.scalapb::scalapbc:0.11.13" | |
import scalapb.ScalaPBC | |
class ProtobufGenerator { | |
def metadataJson: String = | |
s"""{ | |
| "name" : "Protobuf generator", | |
| "version" : "1.0.0", | |
| "supportedExtensions" : ["proto"], | |
| "isReferentiallyTransparent" : true | |
|}""".stripMargin | |
def generate(inputLocation: String, outputLocation: String): Unit = { | |
ScalaPBC.main(Array(s"--scala_out=${outputLocation}", inputLocation)) | |
} | |
} | |
object Main { | |
def main(args: Array[String]) = { | |
val generator = new ProtobufGenerator() | |
args.toList match { | |
case "generate" :: output :: inputs if inputs.nonEmpty => | |
inputs.foreach { input => | |
println(s"Running protobuf generation from [$input] to [$output]") | |
generator.generate(input, output) | |
} | |
case "generator-metadata" :: "protobuf" :: Nil => | |
println("Protobuf generator metadata:") | |
println(generator.metadataJson) | |
case _ => | |
println("Expected usages") | |
println("scala-cli . -- generate <output directory> <input file>*") | |
println("scala-cli . -- generator-metadata protobuf") | |
System.exit(1) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment