ProcessedArgument

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

An Argument delegate implementation that transforms its values .

Functions

copy
Link copied to clipboard
common
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.
finalize
Link copied to clipboard
common
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.
getValue
Link copied to clipboard
common
open operator override fun getValue(thisRef: CliktCommand, property: KProperty<*>): AllT
parameterHelp
Link copied to clipboard
common
open override fun parameterHelp(context: Context): HelpFormatter.ParameterHelp.Argument
Information about this argument for the help output.
postValidate
Link copied to clipboard
common
open override fun postValidate(context: Context)
Called after all of a command's parameters have been finalized to perform validation of the final value.
provideDelegate
Link copied to clipboard
common
open operator override fun provideDelegate(thisRef: CliktCommand, prop: KProperty<*>): ReadOnlyProperty<CliktCommand, AllT>
Implementations must call CliktCommand.registerArgument

Properties

argumentHelp
Link copied to clipboard
common
open override val argumentHelp: String
The description of this argument.
completionCandidates
Link copied to clipboard
common
open override val completionCandidates: CompletionCandidates
Optional set of strings to use when the user invokes shell autocomplete on a value for this argument.
completionCandidatesWithDefault
Link copied to clipboard
helpTags
Link copied to clipboard
common
open override val helpTags: Map<String, String>
Extra information about this argument to pass to the help formatter.
name
Link copied to clipboard
common
open override var name: String
The metavar for this argument.
nvalues
Link copied to clipboard
common
open override val nvalues: Int
The number of values that this argument takes.
required
Link copied to clipboard
common
open override val required: Boolean
If true, an error will be thrown if this argument is not given on the command line.
transformAll
Link copied to clipboard
common
val transformAll: ArgCallsTransformer<AllT, ValueT>
Called in finalize to transform the list of values to the final type.
transformValidator
Link copied to clipboard
common
val transformValidator: ArgValidator<AllT>
Called after all parameters have been finalized to validate the result of transformAll
transformValue
Link copied to clipboard
common
val transformValue: ArgValueTransformer<ValueT>
Called in finalize to transform each value provided to the argument.

Extensions

check
Link copied to clipboard
common
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.
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.
@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.
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.
defaultStdin
Link copied to clipboard
Use - as the default value for an inputStream argument.
defaultStdout
Link copied to clipboard
Use - as the default value for an outputStream argument.
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.
restrictTo
Link copied to clipboard
common
fun <T : Comparable<T>> ProcessedArgument<T, T>.restrictTo(min: T? = null, max: T? = null, clamp: Boolean = false): ProcessedArgument<T, T>
Restrict the argument values to fit into a range.
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.
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.