validate

fun <T : Any> FlagOption<T>.validate(validator: OptionValidator<T>): OptionDelegate<T>

Check the final option value and raise an error if it's not valid.

The validator is called with the final option type (the output of transformAll), and should call fail if the value is not valid. It is not called if the delegate value is null.

fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT, EachT, ValueT>.validate(validator: OptionValidator<AllT>): OptionDelegate<AllT>

Check the final option value and raise an error if it's not valid.

The validator is called with the final option type (the output of transformAll), and should call fail if the value is not valid.

Your validator can also call require to fail automatically if an expression is false, or message to show the user a warning message without aborting.

Example:

val opt by option().int().validate { require(it % 2 == 0) { "value must be even" } }
@JvmName(name = nullableValidate)
inline fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT?, EachT, ValueT>.validate(crossinline validator: OptionValidator<AllT>): OptionDelegate<AllT?>

Check the final option value and raise an error if it's not valid.

The validator is called with the final option type (the output of transformAll), and should call fail if the value is not valid. The validator is not called if the delegate value is null.

Your validator can also call require to fail automatically if an expression is false, or message to show the user a warning message without aborting.

Example:

val opt by option().int().validate { require(it % 2 == 0) { "value must be even" } }