Kli-Composer is a DSL for defining the building blocks of your next command-line interface (CLI) in Kotlin Multiplatform.
Important
This project is still in the early stages of development and is not yet ready for use.
val kli = kliComposer {
command("run", "Run the application") {
val debug: Boolean by flag("--debug", "Enable debug mode")
val fileName: String by argument("input", "Input file name")
val iterations: Int? by option("--iter", "Number of iterations")
execute {
println("Running application")
val optionalValue = value ?: "not set"
if (debug) println("Debug mode enabled for file: $fileName, with $iterations iterations")
else println("Debug mode disabled for file: $fileName")
}
}
command("test", "Run tests") {
execute {
println("Running tests")
}
}
}
When calling the run
method, the CLI will parse the command-line arguments,
flags and options and execute the appropriate command as registered.
fun main() {
val kli = kliComposer {
//...
}
kli.run()
}
Command | Output |
|
|
|
|
|
|
Note
If a description for a command, argument, flag or option is not provided, it will be omitted from the help output.