Clikt (pronounced “clicked”) is a multiplatform Kotlin library that makes writing command line interfaces simple and intuitive. It’s the “Command Line Interface for Kotlin”.
It is designed to make the process of writing command line tools effortless while supporting a wide variety of use cases and allowing advanced customization when needed.
Clikt has:
- arbitrary nesting of commands
- composable, type safe parameter values
- generation of help output and shell autocomplete scripts
- multiplatform packages for JVM, Node.js, and native Linux, Windows and macOS
What does it look like? Here’s a complete example of a simple Clikt program:
class Hello : CliktCommand() {
val count: Int by option().int().default(1).help("Number of greetings")
val name: String by option().prompt("Your name").help("The person to greet")
override fun run() {
repeat(count) {
echo("Hello $name!")
}
}
}
fun main(args: Array<String>) = Hello().main(args)
And here’s what it looks like when run:
The help page is generated for you:
Errors are also taken care of:
Installation¶
Clikt is distributed through Maven Central.
dependencies {
implementation("com.github.ajalt.clikt:clikt:4.2.0")
}
If you’re using Maven instead of Gradle, use <artifactId>clikt-jvm</artifactId>
¶
Multiplatform¶
Clikt supports the following targets: jvm
, mingwX64
, linuxX64
, macosX64
, and js
(for both
Node.js and Browsers). Artifacts for macosArm64 are also published, but not tested with CI. See the
docs for more information about
functionality supported on each target. You’ll need to use Gradle 6 or newer.
Snapshots¶
Snapshot builds are also available
You'll need to add the Sonatype snapshots repository:
repositories {
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
}