OptionWithValues

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

An Option that takes one or more values.

Functions

copy
Link copied to clipboard
common
fun copy(validator: OptionValidator<AllT> = this.transformValidator, names: Set<String> = this.names, metavarWithDefault: ValueWithDefault<Context.() -> String?> = this.metavarWithDefault, nvalues: Int = this.nvalues, help: String = this.optionHelp, hidden: Boolean = this.hidden, helpTags: Map<String, String> = this.helpTags, envvar: String? = this.envvar, valueSourceKey: String? = this.valueSourceKey, valueSplit: Regex? = this.valueSplit, parser: OptionWithValuesParser = this.parser, completionCandidatesWithDefault: ValueWithDefault<CompletionCandidates> = this.completionCandidatesWithDefault): OptionWithValues<AllT, EachT, ValueT>
Create a new option that is a copy of this one with the same transforms.
fun <AllT, EachT, ValueT> copy(transformValue: ValueTransformer<ValueT>, transformEach: ArgsTransformer<ValueT, EachT>, transformAll: CallsTransformer<EachT, AllT>, validator: OptionValidator<AllT>, names: Set<String> = this.names, metavarWithDefault: ValueWithDefault<Context.() -> String?> = this.metavarWithDefault, nvalues: Int = this.nvalues, help: String = this.optionHelp, hidden: Boolean = this.hidden, helpTags: Map<String, String> = this.helpTags, valueSourceKey: String? = this.valueSourceKey, envvar: String? = this.envvar, valueSplit: Regex? = this.valueSplit, parser: OptionWithValuesParser = this.parser, completionCandidatesWithDefault: ValueWithDefault<CompletionCandidates> = this.completionCandidatesWithDefault): OptionWithValues<AllT, EachT, ValueT>
Create a new option that is a copy of this one with different transforms.
finalize
Link copied to clipboard
common
open override fun finalize(context: Context, invocations: List<OptionParser.Invocation>)
Called after this command's argv is parsed to transform and store the option's value.
getValue
Link copied to clipboard
common
open operator override fun getValue(thisRef: ParameterHolder, property: KProperty<*>): AllT
metavar
Link copied to clipboard
common
open override fun metavar(context: Context): String?
A name representing the values for this option that can be displayed to the user.
parameterHelp
Link copied to clipboard
common
open fun parameterHelp(context: Context): HelpFormatter.ParameterHelp.Option?
Information about this option 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: ParameterHolder, prop: KProperty<*>): ReadOnlyProperty<ParameterHolder, AllT>
Implementations must call ParameterHolder.registerOption

Properties

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 option.
completionCandidatesWithDefault
Link copied to clipboard
envvar
Link copied to clipboard
common
val envvar: String?
The environment variable name to use.
groupName
Link copied to clipboard
common
open override var groupName: String? = null
The name of the group, or null if this option should not be grouped in the help output.
helpTags
Link copied to clipboard
common
open override val helpTags: Map<String, String>
Extra information about this option to pass to the help formatter.
hidden
Link copied to clipboard
common
open override val hidden: Boolean
If true, this option should not appear in help output.
metavarWithDefault
Link copied to clipboard
common
val metavarWithDefault: ValueWithDefault<Context.() -> String?>
The metavar to use.
names
Link copied to clipboard
common
open override var names: Set<String>
The names that can be used to invoke this option.
nvalues
Link copied to clipboard
common
open override val nvalues: Int
The number of values that must be given to this option.
optionHelp
Link copied to clipboard
common
open override val optionHelp: String
The description of this option, usually a single line.
parameterGroup
Link copied to clipboard
common
open override var parameterGroup: ParameterGroup? = null
The group that this option belongs to, or null.
parser
Link copied to clipboard
common
open override val parser: OptionWithValuesParser
The parser for this option's values.
secondaryNames
Link copied to clipboard
common
open override val secondaryNames: Set<String>
Names that can be used for a secondary purpose, like disabling flag options.
transformAll
Link copied to clipboard
common
val transformAll: CallsTransformer<EachT, AllT>
Called in finalize to transform all invocations into the final value.
transformEach
Link copied to clipboard
common
val transformEach: ArgsTransformer<ValueT, EachT>
Called in finalize to transform each invocation.
transformValidator
Link copied to clipboard
common
val transformValidator: OptionValidator<AllT>
Called after all parameters have been finalized to validate the output of transformAll
transformValue
Link copied to clipboard
common
val transformValue: ValueTransformer<ValueT>
Called in finalize to transform each value provided to each invocation.
value
Link copied to clipboard
common
open override var value: AllT
The value for this option.
valueSourceKey
Link copied to clipboard
common
open override val valueSourceKey: String?
Optional explicit key to use when looking this option up from a ValueSource
valueSplit
Link copied to clipboard
common
val valueSplit: Regex?
The pattern to split values from the command line on.

Extensions

check
Link copied to clipboard
common
inline fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT, EachT, ValueT>.check(message: String, crossinline validator: (AllT) -> Boolean): OptionDelegate<AllT>
Check the final option value and raise an error if it's not valid.
inline fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT, EachT, ValueT>.check(crossinline lazyMessage: (AllT) -> String = { it.toString() }, crossinline validator: (AllT) -> Boolean): OptionDelegate<AllT>
Check the final argument value and raise an error if it's not valid.
@JvmName(name = nullableCheck)
inline fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT?, EachT, ValueT>.check(message: String, crossinline validator: (AllT) -> Boolean): OptionDelegate<AllT?>
Check the final option value and raise an error if it's not valid.
@JvmName(name = nullableLazyCheck)
inline fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT?, EachT, ValueT>.check(crossinline lazyMessage: (AllT) -> String = { it.toString() }, crossinline validator: (AllT) -> Boolean): OptionDelegate<AllT?>
Check the final argument value and raise an error if it's not valid.
deprecated
Link copied to clipboard
common
fun <AllT, EachT, ValueT> OptionWithValues<AllT, EachT, ValueT>.deprecated(message: String? = "", tagName: String? = "deprecated", tagValue: String = "", error: Boolean = false): OptionDelegate<AllT>
Mark this option as deprecated in the help output.
help
Link copied to clipboard
common
fun <AllT, EachT, ValueT> OptionWithValues<AllT, EachT, ValueT>.help(help: String): OptionWithValues<AllT, EachT, ValueT>
Set the help for this option.
restrictTo
Link copied to clipboard
common
fun <T : Comparable<T>> OptionWithValues<T?, T, T>.restrictTo(min: T? = null, max: T? = null, clamp: Boolean = false): OptionWithValues<T?, T, T>
Restrict the option values to fit into a range.
fun <T : Comparable<T>> OptionWithValues<T?, T, T>.restrictTo(range: ClosedRange<T>, clamp: Boolean = false): OptionWithValues<T?, T, T>
Restrict the option values to fit into a range.
toMap
Link copied to clipboard
common
fun <A, B> OptionWithValues<List<Pair<A, B>>, Pair<A, B>, Pair<A, B>>.toMap(): OptionWithValues<Map<A, B>, Pair<A, B>, Pair<A, B>>
Convert this option's values from a list of pairs into a map with key-value pairs from the list.
unique
Link copied to clipboard
common
Make the multiple option return a unique set of calls

Example:

val opt: Set<Int> by option().int().multiple().unique()
validate
Link copied to clipboard
common
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.
@JvmName(name = nullableValidate)
inline fun <AllT : Any, EachT, ValueT> OptionWithValues<AllT?, EachT, ValueT>.validate(crossinline validator: OptionValidator<AllT>): OptionDelegate<AllT?>
Check the final option value and raise an error if it's not valid.