ProcessedArgument

class ProcessedArgument<AllT, ValueT> : ArgumentDelegate<AllT>

An Argument delegate implementation that transforms its values .

Functions

Link copied to clipboard
fun copy(validator: ArgValidator<AllT> = this.transformValidator, name: String = this.name, nvalues: Int = this.nvalues, required: Boolean = this.required, help: String = this.argumentHelp, helpTags: Map<String, String> = this.helpTags, completionCandidatesWithDefault: ValueWithDefault<CompletionCandidates> = this.completionCandidatesWithDefault): ProcessedArgument<AllT, ValueT>

Create a new argument that is a copy of this one with the same transforms.

fun <AllT, ValueT> copy(transformValue: ArgValueTransformer<ValueT>, transformAll: ArgCallsTransformer<AllT, ValueT>, validator: ArgValidator<AllT>, name: String = this.name, nvalues: Int = this.nvalues, required: Boolean = this.required, help: String = this.argumentHelp, helpTags: Map<String, String> = this.helpTags, completionCandidatesWithDefault: ValueWithDefault<CompletionCandidates> = this.completionCandidatesWithDefault): ProcessedArgument<AllT, ValueT>

Create a new argument that is a copy of this one with different transforms.

Link copied to clipboard
open override fun finalize(context: Context, values: List<String>)

Called after this command's argv is parsed to transform and store the argument's value.

Link copied to clipboard
open fun getValue(thisRef: CliktCommand, property: KProperty<*>): AllT
Link copied to clipboard
open override fun parameterHelp(context: Context): HelpFormatter.ParameterHelp.Argument

Information about this argument for the help output.

Link copied to clipboard
open override fun postValidate(context: Context)

Called after all of a command's parameters have been finalized to perform validation of the final value.

Link copied to clipboard
open operator override fun provideDelegate(thisRef: CliktCommand, prop: KProperty<*>): <ERROR CLASS><CliktCommand, AllT>

Implementations must call CliktCommand.registerArgument

Properties

Link copied to clipboard
open override val argumentHelp: String

The description of this argument.

Link copied to clipboard
open override val completionCandidates: CompletionCandidates

Optional set of strings to use when the user invokes shell autocomplete on a value for this argument.

Link copied to clipboard
Link copied to clipboard
open override val helpTags: Map<String, String>

Extra information about this argument to pass to the help formatter.

Link copied to clipboard
open override var name: String

The metavar for this argument.

Link copied to clipboard
open override val nvalues: Int

The number of values that this argument takes.

Link copied to clipboard
open override val required: Boolean

If true, an error will be thrown if this argument is not given on the command line.

Link copied to clipboard
val transformAll: ArgCallsTransformer<AllT, ValueT>

Called in finalize to transform the list of values to the final type.

Link copied to clipboard
val transformValidator: ArgValidator<AllT>

Called after all parameters have been finalized to validate the result of transformAll

Link copied to clipboard
val transformValue: ArgValueTransformer<ValueT>

Called in finalize to transform each value provided to the argument.

Extensions

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

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, defaultForHelp: String = value.toString()): 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(defaultForHelp: String, crossinline value: () -> T): ArgumentDelegate<T>

If the argument is not given, call value and use its return value instead of throwing an error.

inline fun <T : Any> ProcessedArgument<T, T>.defaultLazy(crossinline value: () -> T): ArgumentDelegate<T>
Link copied to clipboard
fun ProcessedArgument<InputStream, InputStream>.defaultStdin(): ArgumentDelegate<InputStream>

Use - as the default value for an inputStream argument.

Link copied to clipboard
fun ProcessedArgument<OutputStream, OutputStream>.defaultStdout(): ArgumentDelegate<OutputStream>

Use - as the default value for an outputStream argument.

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 <T : Comparable<T>> ProcessedArgument<T, T>.restrictTo(min: T? = null, max: T? = null, clamp: Boolean = false): ProcessedArgument<T, T>
fun <T : Comparable<T>> ProcessedArgument<T, T>.restrictTo(range: ClosedRange<T>, clamp: Boolean = false): ProcessedArgument<T, T>

Restrict the argument values to fit into a range.

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.

fun <AllInT, ValueT, AllOutT> ProcessedArgument<AllInT, ValueT>.transformAll(nvalues: Int?, required: Boolean?, defaultForHelp: String?, transform: ArgCallsTransformer<AllOutT, ValueT>): ProcessedArgument<AllOutT, ValueT>
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.