Converter

interface Converter<out T>

Converts a raw command-line string into a typed value. Implement this to support a type beyond the built-ins.

object SlugConverter : Converter<String> {
override val typeName: String = "slug"
override fun convert(raw: String): String {
require(raw.all { it.isLetterOrDigit() || it == '-' }) { "not a slug: '$raw'" }
return raw.lowercase()
}
}

Type Parameters

T

the produced value type.

Inheritors

Properties

Link copied to clipboard
open val typeName: String

A short name for the target type (for example "Int"), shown in help and error messages.

Functions

Link copied to clipboard
abstract fun convert(raw: String): T

Parses raw into a value of type T.