clikt / com.github.ajalt.clikt.parameters.arguments / convert

convert

inline fun Any, ValueT : Any> ProcessedArgument.convert(completionCandidates: CompletionCandidates = completionCandidatesWithDefault.default, crossinline conversion: ArgValueConverter): ProcessedArgument

Convert the argument’s values.

The conversion is called once for each value given. 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 argument().convert { it.toBigDecimal() } val fileText: ByteArray by argument().file().convert { it.readBytes() }

Parameters

completionCandidates - candidates to use when completing this argument in shell autocomplete, if no candidates are specified in argument