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

Types

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

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

Link copied to clipboard
interface Argument

A positional parameter to a command.

Link copied to clipboard
interface ArgumentDelegate<out T> : Argument

An argument that functions as a property delegate

Link copied to clipboard
class ArgumentTransformContext(argument: Argument, context: Context) : Argument

A receiver for argument transformers.

Link copied to clipboard
typealias ArgValidator<AllT> = ArgumentTransformContext.(AllT) -> Unit

A callback validates the final argument type

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

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

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

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

Link copied to clipboard
class ProcessedArgument<AllT, ValueT> : ArgumentDelegate<AllT>

An Argument delegate implementation that transforms its values .

Link copied to clipboard
typealias RawArgument = ProcessedArgument<String, String>

Functions

Link copied to clipboard
fun CliktCommand.argument(name: String = "", help: String = "", helpTags: Map<String, String> = emptyMap(), completionCandidates: CompletionCandidates? = null): RawArgument

Create a property delegate argument.

Link copied to clipboard
inline fun <AllT : Any, ValueT> ProcessedArgument<AllT, ValueT>.check(crossinline lazyMessage: (AllT) -> String = { it.toString() }, crossinline validator: (AllT) -> Boolean): ArgumentDelegate<AllT>
inline fun <AllT : Any, ValueT> ProcessedArgument<AllT, ValueT>.check(message: String, crossinline validator: (AllT) -> Boolean): ArgumentDelegate<AllT>
inline fun <AllT : Any, ValueT> ProcessedArgument<AllT?, ValueT>.check(crossinline lazyMessage: (AllT) -> String = { it.toString() }, crossinline validator: (AllT) -> Boolean): ArgumentDelegate<AllT?>
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.

Link copied to clipboard
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.

Link copied to clipboard
fun <T : Any> ProcessedArgument<T, T>.default(value: T): ArgumentDelegate<T>

If the argument is not given, use value instead of throwing an error.

Link copied to clipboard
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.

Link copied to clipboard
fun <AllT, ValueT> ProcessedArgument<AllT, ValueT>.help(help: String): ProcessedArgument<AllT, ValueT>

Set the help for this argument.

Link copied to clipboard
fun <T : Any> ProcessedArgument<T, T>.multiple(required: Boolean = false, default: List<T> = emptyList()): ProcessedArgument<List<T>, T>

Accept any number of values to this argument.

Link copied to clipboard
fun <AllT : Any, ValueT> ProcessedArgument<AllT, ValueT>.optional(): ProcessedArgument<AllT?, ValueT>

Return null instead of throwing an error if no value is given.

Link copied to clipboard
fun <T : Any> ProcessedArgument<T, T>.pair(): ProcessedArgument<<ERROR CLASS><T, T>, T>

Require exactly two values to this argument, and store them in a Pair.

Link copied to clipboard
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.

Link copied to clipboard
fun <T : Any> ProcessedArgument<T, T>.triple(): ProcessedArgument<<ERROR CLASS><T, T, T>, T>

Require exactly three values to this argument, and store them in a Triple

Link copied to clipboard
fun <T : Any> ProcessedArgument<List<T>, T>.unique(): ProcessedArgument<Set<T>, T>

Only store unique values for this argument

Link copied to clipboard
fun <AllT : Any, ValueT> ProcessedArgument<AllT, ValueT>.validate(validator: ArgValidator<AllT>): ArgumentDelegate<AllT>
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.