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

ProcessedArgument

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

An Argument delegate implementation that transforms its values .

Constructors

<init>

ProcessedArgument(name: String, nvalues: Int, required: Boolean, help: String, transformValue: ArgValueTransformer<ValueT>, transformAll: ArgCallsTransformer<AllT, ValueT>)

An Argument delegate implementation that transforms its values .

Properties

help

val help: String

The description of this argument.

name

var name: String

The metavar for this argument.

nvalues

val nvalues: Int

The number of values that this argument takes.

parameterHelp

val parameterHelp: Argument

Information about this argument for the help output.

required

val required: Boolean

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

transformAll

val transformAll: ArgCallsTransformer<AllT, ValueT>

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

transformValue

val transformValue: ArgValueTransformer<ValueT>

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

Functions

copy

fun <AllT, ValueT> copy(transformValue: ArgValueTransformer<ValueT>, transformAll: ArgCallsTransformer<AllT, ValueT>, name: String = this.name, nvalues: Int = this.nvalues, required: Boolean = this.required, help: String = this.help): ProcessedArgument<AllT, ValueT>

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

finalize

fun finalize(context: Context, values: List<String>): Unit

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

getValue

fun getValue(thisRef: CliktCommand, property: KProperty<*>): AllT

provideDelegate

operator fun provideDelegate(thisRef: CliktCommand, prop: KProperty<*>): ReadOnlyProperty<CliktCommand, AllT>

Implementations must call CliktCommand.registerArgument

Extension Functions

choice

fun <T : Any> RawArgument.choice(choices: Map<String, T>): ProcessedArgument<T, T>
fun <T : Any> RawArgument.choice(vararg choices: Pair<String, T>): ProcessedArgument<T, T>

Convert the argument based on a fixed set of values.

fun RawArgument.choice(vararg choices: String): ProcessedArgument<String, String>

Restrict the argument to a fixed set of values.

convert

fun <T : Any> RawArgument.convert(conversion: ArgValueTransformer<T>): ProcessedArgument<T, T>

Convert the argument's values.

default

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

fun <T : Any> ProcessedArgument<T, T>.defaultLazy(value: () -> T): ArgumentDelegate<T>

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

double

fun RawArgument.double(): ProcessedArgument<Double, Double>

Convert the argument values to a Double

file

fun RawArgument.file(exists: Boolean = false, fileOkay: Boolean = true, folderOkay: Boolean = true, writable: Boolean = false, readable: Boolean = false): ProcessedArgument<File, File>

Convert the argument to a File.

float

fun RawArgument.float(): ProcessedArgument<Float, Float>

Convert the argument values to a Float

int

fun RawArgument.int(): ProcessedArgument<Int, Int>

Convert the argument values to an Int

long

fun RawArgument.long(): ProcessedArgument<Long, Long>

Convert the argument values to a Long

multiple

fun <T : Any> ProcessedArgument<T, T>.multiple(required: Boolean = false): ProcessedArgument<List<T>, T>

Accept any number of values to this argument.

optional

fun <AllT : Any, ValueT> ProcessedArgument<AllT, ValueT>.optional(): ProcessedArgument<AllT?, ValueT>

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

pair

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.

path

fun RawArgument.path(exists: Boolean = false, fileOkay: Boolean = true, folderOkay: Boolean = true, writable: Boolean = false, readable: Boolean = false, fileSystem: FileSystem = FileSystems.getDefault()): ProcessedArgument<Path, Path>

Convert the argument to a Path.

restrictTo

fun <T> ProcessedArgument<T, T>.restrictTo(min: T? = null, max: T? = null, clamp: Boolean = false): ProcessedArgument<T, T> where T : Number, T : Comparable<T>
fun <T> ProcessedArgument<T, T>.restrictTo(range: ClosedRange<T>, clamp: Boolean = false): ProcessedArgument<T, T> where T : Number, T : Comparable<T>

Restrict the argument values to fit into a range.

transformAll

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

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 Triple

unique

fun <T : Any> ProcessedArgument<List<T>, T>.unique(): ProcessedArgument<Set<T>, T>

Only store unique values for this argument

validate

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.