clikt / com.github.ajalt.clikt.parameters.types / restrictTo

restrictTo

fun ProcessedArgument.restrictTo(min: T? = null, max: T? = null, clamp: Boolean = false): ProcessedArgument where T : Number, T : Comparable

Restrict the argument values to fit into a range.

By default, conversion fails if the value is outside the range, but if clamp is true, the value will be silently clamped to fit in the range.

Example:

argument().int().restrictTo(max=10, clamp=true)

fun ProcessedArgument.restrictTo(range: ClosedRange, clamp: Boolean = false): ProcessedArgument where T : Number, T : Comparable

Restrict the argument values to fit into a range.

By default, conversion fails if the value is outside the range, but if clamp is true, the value will be silently clamped to fit in the range.

Example:

argument().int().restrictTo(1..10, clamp=true)

fun OptionWithValues.restrictTo(min: T? = null, max: T? = null, clamp: Boolean = false): OptionWithValues where T : Number, T : Comparable

Restrict the option values to fit into a range.

By default, conversion fails if the value is outside the range, but if clamp is true, the value will be silently clamped to fit in the range.

Example:

option().int().restrictTo(max=10, clamp=true)

fun OptionWithValues.restrictTo(range: ClosedRange, clamp: Boolean = false): OptionWithValues where T : Number, T : Comparable

Restrict the option values to fit into a range.

By default, conversion fails if the value is outside the range, but if clamp is true, the value will be silently clamped to fit in the range.

Example:

option().int().restrictTo(1..10, clamp=true)