Package com.github.ajalt.clikt.parameters.arguments

Types

ArgCallsTransformer
Link copied to clipboard
common
typealias ArgCallsTransformer<AllT, EachT> = ArgumentTransformContext.(List<EachT>) -> AllT

A callback that transforms all the values into the final argument type

Argument
Link copied to clipboard
common
interface Argument
A positional parameter to a command.
ArgumentDelegate
Link copied to clipboard
common
interface ArgumentDelegate<out T> : Argument, ReadOnlyProperty<CliktCommand, T>
An argument that functions as a property delegate
ArgumentTransformContext
Link copied to clipboard
common
class ArgumentTransformContext(argument: Argument, context: Context) : Argument
A receiver for argument transformers.
ArgValidator
Link copied to clipboard
common
typealias ArgValidator<AllT> = ArgumentTransformContext.(AllT) -> Unit

A callback validates the final argument type

ArgValueConverter
Link copied to clipboard
common
typealias ArgValueConverter<InT, ValueT> = ArgumentTransformContext.(InT) -> ValueT

A callback that transforms a single value from one type to another

ArgValueTransformer
Link copied to clipboard
common
typealias ArgValueTransformer<T> = ArgValueConverter<String, T>

A callback that transforms a single value from a string to the value type

ProcessedArgument
Link copied to clipboard
common
class ProcessedArgument<AllT, ValueT> : ArgumentDelegate<AllT>
An Argument delegate implementation that transforms its values .
RawArgument
Link copied to clipboard
common
typealias RawArgument = ProcessedArgument<String, String>

Functions

argument
Link copied to clipboard
common
fun CliktCommand.argument(name: String = "", help: String = "", helpTags: Map<String, String> = emptyMap(), completionCandidates: CompletionCandidates? = null): RawArgument
Create a property delegate argument.
check
Link copied to clipboard
common
inline fun <AllT : Any, ValueT> ProcessedArgument<AllT, ValueT>.check(crossinline lazyMessage: (AllT) -> String = { it.toString() }, crossinline validator: (AllT) -> Boolean): ArgumentDelegate<AllT>
Check the final argument value and raise an error if it's not valid.
inline fun <AllT : Any, ValueT> ProcessedArgument<AllT, ValueT>.check(message: String, crossinline validator: (AllT) -> Boolean): ArgumentDelegate<AllT>
Check the final argument value and raise an error if it's not valid.
@JvmName(name = nullableLazyCheck)
inline fun <AllT : Any, ValueT> ProcessedArgument<AllT?, ValueT>.check(crossinline lazyMessage: (AllT) -> String = { it.toString() }, crossinline validator: (AllT) -> Boolean): ArgumentDelegate<AllT?>
Check the final argument value and raise an error if it's not valid.
@JvmName(name = nullableCheck)
inline fun <AllT : Any, ValueT> ProcessedArgument<AllT?, ValueT>.check(message: String, crossinline validator: (AllT) -> Boolean): ArgumentDelegate<AllT?>
Check the final argument value and raise an error if it's not valid.
convert
Link copied to clipboard
common
inline fun <InT : Any, ValueT : Any> ProcessedArgument<InT, InT>.convert(completionCandidates: CompletionCandidates = completionCandidatesWithDefault.default, crossinline conversion: ArgValueConverter<InT, ValueT>): ProcessedArgument<ValueT, ValueT>
Convert the argument's values.
default
Link copied to clipboard
common
fun <T : Any> ProcessedArgument<T, T>.default(value: T): ArgumentDelegate<T>
If the argument is not given, use value instead of throwing an error.
defaultLazy
Link copied to clipboard
common
inline fun <T : Any> ProcessedArgument<T, T>.defaultLazy(crossinline value: () -> T): ArgumentDelegate<T>
If the argument is not given, call value and use its return value instead of throwing an error.
help
Link copied to clipboard
common
fun <AllT, ValueT> ProcessedArgument<AllT, ValueT>.help(help: String): ProcessedArgument<AllT, ValueT>
Set the help for this argument.
multiple
Link copied to clipboard
common
fun <T : Any> ProcessedArgument<T, T>.multiple(required: Boolean = false): ProcessedArgument<List<T>, T>
Accept any number of values to this argument.
optional
Link copied to clipboard
common
fun <AllT : Any, ValueT> ProcessedArgument<AllT, ValueT>.optional(): ProcessedArgument<AllT?, ValueT>
Return null instead of throwing an error if no value is given.
pair
Link copied to clipboard
common
fun <T : Any> ProcessedArgument<T, T>.pair(): ProcessedArgument<Pair<T, T>, T>
Require exactly two values to this argument, and store them in a Pair.
transformAll
Link copied to clipboard
common
fun <AllInT, ValueT, AllOutT> ProcessedArgument<AllInT, ValueT>.transformAll(nvalues: Int? = null, required: Boolean? = null, transform: ArgCallsTransformer<AllOutT, ValueT>): ProcessedArgument<AllOutT, ValueT>
Transform all values to the final argument type.
triple
Link copied to clipboard
common
fun <T : Any> ProcessedArgument<T, T>.triple(): ProcessedArgument<Triple<T, T, T>, T>
Require exactly three values to this argument, and store them in a TripleThis must be called after converting the value type, and before other transforms.
unique
Link copied to clipboard
common
fun <T : Any> ProcessedArgument<List<T>, T>.unique(): ProcessedArgument<Set<T>, T>
Only store unique values for this argument

Example:

val arg: Set<Int> by argument().int().multiple().unique()
validate
Link copied to clipboard
common
fun <AllT : Any, ValueT> ProcessedArgument<AllT, ValueT>.validate(validator: ArgValidator<AllT>): ArgumentDelegate<AllT>
Check the final argument value and raise an error if it's not valid.
@JvmName(name = nullableValidate)
fun <AllT : Any, ValueT> ProcessedArgument<AllT?, ValueT>.validate(validator: ArgValidator<AllT>): ArgumentDelegate<AllT?>
Check the final argument value and raise an error if it's not valid.