optional Value
fun <ValueT : Any> NullableOption<ValueT, ValueT>.optionalValue(default: ValueT, acceptsUnattachedValue: Boolean = true): NullableOption<ValueT, ValueT>
Allow this option to be specified with or without an explicit value.
If the option is specified on the command line without a value, default will be used.
To avoid ambiguity when combined with arguments, you can set acceptsUnattachedValue to false
to require that the option's value be specified like --foo=bar
rather than --foo bar
.
You can use optionalValueLazy if you need to reference other parameters.
Example
val log by option().optionalValue("verbose").default("none")
> ./tool --log=debug
log level == debug
> ./tool --log
log level == verbose
> ./tool
log level == none
Content copied to clipboard