defaultLazy

inline fun <T : Any> FlagOption<T?>.defaultLazy(defaultForHelp: String = "", crossinline value: () -> T): FlagOption<T>

Set a default value for an option from a lazy builder which is only called if the default value is used.

Parameters

defaultForHelp

The help text for this option's default value if the help formatter is configured to show them. By default, the default value is not shown in help.

inline fun <EachT : Any, ValueT> NullableOption<EachT, ValueT>.defaultLazy(defaultForHelp: String = "", 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.

You can customize how the default is shown to the user with defaultForHelp. The default value is an empty string, so if you have the help formatter configured to show values, you should set this value manually.

Example:

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