Skip to content

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

restrictTo

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

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.

This must be called before transforms like pair, default, or multiple, since it checks each individual value.

Example:

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

fun Comparable\> ProcessedArgument.restrictTo(range: ClosedRange, clamp: Boolean = false): ProcessedArgument

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.

This must be called before transforms like pair, default, or multiple, since it checks each individual value.

Example:

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

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

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.

This must be called before transforms like pair, default, or multiple, since it checks each individual value.

Example:

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

fun Comparable\> OptionWithValues.restrictTo(range: ClosedRange, clamp: Boolean = false): OptionWithValues

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.

This must be called before transforms like pair, default, or multiple, since it checks each individual value.

Example:

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