clikt / com.github.ajalt.clikt.parameters.options

Package com.github.ajalt.clikt.parameters.options

Types

EagerOption

class EagerOption : Option

An Option with no values that is finalized before other types of options.

FlagOption

class FlagOption<T> : OptionDelegate<T>

An Option that has no values.

Option

interface Option

An optional command line parameter that takes a fixed number of values.

OptionCallTransformContext

class OptionCallTransformContext : Option

A receiver for options transformers.

OptionDelegate

interface OptionDelegate<out T> : Option, ReadOnlyProperty<CliktCommand, T>

An option that functions as a property delegate

OptionTransformContext

class OptionTransformContext : Option

A receiver for options transformers.

OptionWithValues

class OptionWithValues<AllT, EachT, ValueT> : OptionDelegate<AllT>

An Option that takes one or more values.

Type Aliases

ArgsTransformer

typealias ArgsTransformer<ValueT, EachT> = OptionCallTransformContext.(List<ValueT>) -> EachT

A callback that transforms all the values for a call to the call type.

CallsTransformer

typealias CallsTransformer<EachT, AllT> = OptionTransformContext.(List<EachT>) -> AllT

A callback that transforms all of the calls to the final option type.

NullableOption

typealias NullableOption<EachT, ValueT> = OptionWithValues<EachT?, EachT, ValueT>

OptionValidator

typealias OptionValidator<AllT> = OptionTransformContext.(AllT) -> Unit

A callback validates the final option type

RawOption

typealias RawOption = NullableOption<String, String>

ValueTransformer

typealias ValueTransformer<ValueT> = OptionCallTransformContext.(String) -> ValueT

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

Functions

convert

fun <T : Any> RawOption.convert(metavar: String = "VALUE", envvarSplit: Regex = this.envvarSplit, conversion: ValueTransformer<T>): NullableOption<T, T>

Convert the option value type.

counted

fun RawOption.counted(): FlagOption<Int>

Turn an option into a flag that counts the number of times the option occurs on the command line.

default

fun <T : Any> FlagOption<T?>.default(value: T): FlagOption<T>

Set a default value for a option.

fun <EachT : Any, ValueT> NullableOption<EachT, ValueT>.default(value: EachT): OptionWithValues<EachT, EachT, ValueT>

If the option is not called on the command line (and is not set in an envvar), use value for the option.

defaultLazy

fun <EachT : Any, ValueT> NullableOption<EachT, ValueT>.defaultLazy(value: () -> EachT): OptionWithValues<EachT, EachT, ValueT>

If the option is not called on the command line (and is not set in an envvar), call the value and use its return value for the option.

flag

fun RawOption.flag(vararg secondaryNames: String, default: Boolean = false): FlagOption<Boolean>

Turn an option into a boolean flag.

multiple

fun <EachT : Any, ValueT> NullableOption<EachT, ValueT>.multiple(default: List<EachT> = emptyList()): OptionWithValues<List<EachT>, EachT, ValueT>

Make the option return a list of calls; each item in the list is the value of one call.

option

fun CliktCommand.option(vararg names: String, help: String = "", metavar: String? = null, hidden: Boolean = false, envvar: String? = null): RawOption

Create a property delegate option.

pair

fun <EachT : Any, ValueT> NullableOption<EachT, ValueT>.pair(): NullableOption<Pair<ValueT, ValueT>, ValueT>

Change to option to take two values, held in a Pair

prompt

fun <T : Any> NullableOption<T, T>.prompt(text: String? = null, default: String? = null, hideInput: Boolean = false, requireConfirmation: Boolean = false, confirmationPrompt: String = "Repeat for confirmation: ", promptSuffix: String = ": ", showDefault: Boolean = true): OptionWithValues<T, T, T>

If the option isn't given on the command line, prompt the user for manual input.

required

fun <EachT : Any, ValueT> NullableOption<EachT, ValueT>.required(): OptionWithValues<EachT, EachT, ValueT>

If the option is not called on the command line (and is not set in an envvar), throw a MissingParameter.

switch

fun <T : Any> RawOption.switch(choices: Map<String, T>): FlagOption<T?>
fun <T : Any> RawOption.switch(vararg choices: Pair<String, T>): FlagOption<T?>

Turn an option into a set of flags that each map to a value.

transformAll

fun <AllT, EachT : Any, ValueT> NullableOption<EachT, ValueT>.transformAll(transform: CallsTransformer<EachT, AllT>): OptionWithValues<AllT, EachT, ValueT>

Transform all calls to the option to the final option type.

transformValues

fun <EachInT : Any, EachOutT : Any, ValueT> NullableOption<EachInT, ValueT>.transformValues(nvalues: Int, transform: ArgsTransformer<ValueT, EachOutT>): NullableOption<EachOutT, ValueT>

Change the number of values that this option takes.

triple

fun <EachT : Any, ValueT> NullableOption<EachT, ValueT>.triple(): NullableOption<Triple<ValueT, ValueT, ValueT>, ValueT>

Change to option to take three values, held in a Triple

validate

fun <T : Any> FlagOption<T>.validate(validator: OptionValidator<T>): OptionDelegate<T>
fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT, EachT, ValueT>.validate(validator: OptionValidator<AllT>): OptionDelegate<AllT>

Check the final option value and raise an error if it's not valid.

versionOption

fun <T : CliktCommand> T.versionOption(version: String, help: String = "Show the version and exit.", names: Set<String> = setOf("--version"), message: (String) -> String = { "$commandName version $it" }): T

Add an eager option to this command that, when invoked, prints a version message and exits.