validate

fun validate(message: String = "Invalid value for @name: @value", predicate: (T) -> Boolean): OptionBuilder<T>(source)

Adds a validator that checks the parsed value against the given predicate. The validator only runs if the value is not null.

Parameters

message

Template message for validation errors. Supports:

  • @name: property name

  • @value: the invalid value (properly formatted)

  • @switches: option switches (e.g. "--port|-p")

predicate

Function that returns true if the value is valid


fun validate(vararg validations: Pair<String, (T) -> Boolean>): OptionBuilder<T>(source)

Adds multiple validators at once.

Parameters

validations

Pairs of (message template, predicate) for validation