Skip to content

Converter<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()
    }
}
Converter.kt

Properties

typeName

open val typeName: String

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

Converter.kt

Functions

convert

abstract fun convert(raw: String): T

Parses raw into a value of type T.

ThrowsArgotConversionException

if raw cannot be converted.

Converter.kt

Released under the Apache License 2.0.