clikt / com.github.ajalt.clikt.parameters.options / defaultLazy

defaultLazy

inline fun <EachT : Any, ValueT> NullableOption<EachT, ValueT>.defaultLazy(crossinline value: () -> EachT): OptionWithValues<EachT, EachT, ValueT>

If the option is not called on the command line (and is not set in an envvar), call the value and use its return value for the option.

This must be applied after all other transforms. If the option is given on the command line, value will not be called.

Example:

val opt: Pair<Int, Int> by option().int().pair().defaultLazy { expensiveOperation() }