diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 550687e..0105d77 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,7 @@ okio = "3.3.0" antlr = "org.antlr:antlr4:4.9.3" apacheThrift = "org.apache.thrift:libthrift:0.17.0" atomicfu-common = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "atomicfu" } -clikt = "com.github.ajalt.clikt:clikt:3.1.0" +clikt = "com.github.ajalt.clikt:clikt:5.0.1" dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.0" guava = "com.google.guava:guava:33.3.1-jre" kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" } diff --git a/thrifty-compiler/src/main/kotlin/com/bendb/thrifty/compiler/ThriftyCompiler.kt b/thrifty-compiler/src/main/kotlin/com/bendb/thrifty/compiler/ThriftyCompiler.kt index 299c1db..f58758f 100644 --- a/thrifty-compiler/src/main/kotlin/com/bendb/thrifty/compiler/ThriftyCompiler.kt +++ b/thrifty-compiler/src/main/kotlin/com/bendb/thrifty/compiler/ThriftyCompiler.kt @@ -27,7 +27,8 @@ import com.bendb.thrifty.schema.LoadFailedException import com.bendb.thrifty.schema.Loader import com.bendb.thrifty.schema.Schema import com.github.ajalt.clikt.core.CliktCommand -import com.github.ajalt.clikt.output.TermUi +import com.github.ajalt.clikt.core.Context +import com.github.ajalt.clikt.core.main import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.arguments.multiple import com.github.ajalt.clikt.parameters.options.default @@ -113,7 +114,6 @@ class ThriftyCompiler { private val cli = object : CliktCommand( name = "thrifty-compiler", - help = "Generate Java or Kotlin code from .thrift files" ) { val outputDirectory: Path by option("-o", "--out", help = "the output directory for generated files") .path(canBeFile = false, canBeDir = true) @@ -173,6 +173,10 @@ class ThriftyCompiler { help = "When set, unknown values found when decoding will throw an exception. Otherwise, it uses null/default values.") .flag("--no-fail-on-unknown-enum-values", default = true) + override fun help(context: Context): String { + return "Generate Kotlin code from .thrift files" + } + override fun run() { val loader = Loader() for (thriftFile in thriftFiles) { @@ -250,21 +254,24 @@ class ThriftyCompiler { val specs = gen.generate(schema) + specs.forEach { it.writeTo(outputDirectory) } } } - fun compile(args: Array) = cli.main(args) + fun compile(args: Array) { + try { + cli.main(args) + } catch (e: Exception) { + cli.echo("Unhandled exception", err = true) + e.printStackTrace(System.err) + exitProcess(1) + } + } companion object { @JvmStatic fun main(args: Array) { - try { - ThriftyCompiler().compile(args) - } catch (e: Exception) { - TermUi.echo("Unhandled exception", err = true) - e.printStackTrace(System.err) - exitProcess(1) - } + ThriftyCompiler().compile(args) } } }