Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clikt 3.1.0 -> 5.0.1 #8

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -250,21 +254,24 @@ class ThriftyCompiler {

val specs = gen.generate(schema)


specs.forEach { it.writeTo(outputDirectory) }
}
}

fun compile(args: Array<String>) = cli.main(args)
fun compile(args: Array<String>) {
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<String>) {
try {
ThriftyCompiler().compile(args)
} catch (e: Exception) {
TermUi.echo("Unhandled exception", err = true)
e.printStackTrace(System.err)
exitProcess(1)
}
ThriftyCompiler().compile(args)
}
}
}
Loading