Kotlin-er CLI

A different take on making command line programs, emphasizing development speed over customization


Auto-deployed to Maven Central after passing unit tests using GitHub Actions

release status
snapshot status


dependencies {


import com.lightningkite.kotlinercli.cli
import java.io.File

fun main(args: Array<String>) = cli(args, ::runServer, ::migrate, ::dump, ::deleteItems)

fun runServer(host: String = "", port: Int = 8080) = println("Running the server at $host on port $port")
fun migrate(version: Int) = println("Upgrading the database")
fun dump(to: File) = println("Dumping to a file")
fun deleteItems(vararg ids: Int) = println("Deleting ${ids.joinToString()}")

$ myProgram
Available commands:
runServer(host: String = ..., port: Int = ...): Unit
migrate(version: Int): Unit
dump(to: File): Unit
deleteItems(ids: IntArray): Unit

$ myProgram runServer --help
--host: String (optional)
--port: Int (optional)

$ myProgram runServer
Running the server at with port 8000

$ myProgram runServer 8080
Running the server at with port 8080

$ myProgram runServer --port 8080
Running the server at with port 8080

$ myProgram deleteItems 1 2 3
Deleting 1, 2, 3

Supported Features

  • Primitive Types
  • Types with a constructor that takes a String
  • Ordered Arguments
  • Named Arguments
  • Default Arguments
  • Variadic Arguments
  • Boolean Flags (i.e. using --flag for flag=true)
  • Description Annotation – add the annotation to provide more documentation about functions and parameters.

Potential Features

  • Annotation to automatically register functions to expose to the CLI
    • Questionable security-wise – makes it easy to insert functionality with no obvious connection.
  • Compiler plugin to read KDoc for runtime documentation

Deliberately unsupported features

  • Object types without a string constructor – No good way to represent in the command line.
  • Expose all functions in the command line – would be a potential security problem


View Github