Arguments

abstract class Arguments(val programName: String = "program", val description: String = "", val version: String? = null)

Base class for declaring a command line with by delegates.

Declare each parameter with option, flag, or argument. Reading a delegated property before the arguments have been parsed throws.

class ServerArgs : Arguments(programName = "serve", description = "Run the server") {
val host: String by option("--host", help = "Bind host").default("0.0.0.0")
val port: Int by option("--port", "-p", help = "Port").int().required()
val verbose: Boolean by flag("--verbose", "-v", help = "Verbose logging")
val files: List<String> by argument(help = "Files to serve").multiple()
}

fun main(argv: Array<String>) {
val args = ServerArgs().parsed(argv)
println("serving ${args.files} on ${args.host}:${args.port}")
}

Parameters

programName

the program name shown in usage and help.

description

a one-line description shown at the top of --help.

version

when set, --version is recognized.

Constructors

Link copied to clipboard
constructor(programName: String = "program", description: String = "", version: String? = null)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard