If I wanted to write a console app in Kotlin, is t...
# getting-started
m
If I wanted to write a console app in Kotlin, is there a go-to standard CLI parser? I see a few on github, but wondered if there was one just everyone used.
r
#clikt is quite popular - not sure if it ranks as go-to standard yet.
a
https://github.com/Kotlin/kotlinx-cli would be the ‘standard’, because it’s owned by JetBrains, but Clikt is better
e
Java parsers like picocli also work, and they have examples in Kotlin too. but in my experience Clikt is more common in Kotlin-first projects
m
Will look at these, thanks.
a
for some CLI apps I found it easier to pass in a JSON5 file as the only arg (or default to an environment variable) and use Kotlinx Serialization json5k to decode it to a MyCliAppArgs class I had a vague idea a while ago for using creating a Kotlinx Serialization format for decoding CLI args… https://kotlinlang.slack.com/archives/C7A1U5PTM/p1668606897420759
a
PicoCLI is a good library for this https://picocli.info/
👍 1
r
FWIW I wrote up some notes on how I like to use Clikt: https://blog.lidalia.org.uk/2023/06/working-with-clikt.html
thank you color 1