Skip to content

Command

Marks a class whose primary-constructor parameters declare a command-line interface.

The Argot KSP processor reads the primary constructor — each parameter annotated with Option, Flag, or Argument — and generates a sibling parse<ClassName>(argv): ClassName function. The class itself is never modified.

@Command(name = "serve", description = "Run the server")
data class ServeArgs(
    @Option(names = ["--host"], help = "Bind host", default = "0.0.0.0") val host: String,
    @Option(names = ["--port", "-p"], help = "Port") val port: Int,
    @Flag(names = ["--verbose", "-v"], help = "Verbose") val verbose: Boolean = false,
    @Argument(help = "Files to serve") val files: List<String>,
)
// Generated: fun parseServeArgs(argv: Array<String>): ServeArgs
Command.kt

Properties

description

val description: String
Command.kt

name

val name: String
Command.kt

Released under the Apache License 2.0.