convert
Convert the option's value type.
The conversion is called once for each value in each invocation of the option. If any errors are thrown, they are caught and a BadParameterValue is thrown with the error message. You can call fail to throw a BadParameterValue manually.
You can call convert
more than once to wrap the result of the previous convert
, but it cannot be called after transformAll (e.g. multiple) or transformValues (e.g. pair).
Example
val bd: BigDecimal? by option().convert { it.toBigDecimal() }
val fileText: ByteArray? by option().file().convert { it.readBytes() }
Parameters
The metavar for the type. Overridden by a metavar passed to option.
candidates to use when completing this option in shell autocomplete, if no candidates are specified in option
Convert the option's value type.
The conversion is called once for each value in each invocation of the option. If any errors are thrown, they are caught and a BadParameterValue is thrown with the error message. You can call fail to throw a BadParameterValue manually.
You can call convert
more than once to wrap the result of the previous convert
, but it cannot be called after transformAll (e.g. multiple) or transformValues (e.g. pair).
Example
val bd: BigDecimal? by option().convert { it.toBigDecimal() }
val fileText: ByteArray? by option().file().convert { it.readBytes() }
Parameters
candidates to use when completing this option in shell autocomplete, if no candidates are specified in option
Convert this flag's value type.
The conversion is called once with the final value of the option. If any errors are thrown, they are caught and a BadParameterValue is thrown with the error message. You can call fail to throw a BadParameterValue manually.
Example
val loud by option().flag().convert { if (it) Volume.Loud else Volume.Soft }