Skip to content

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

OptionWithValues

class OptionWithValues : OptionDelegate, GroupableOption

An Option that takes one or more values.

Properties

Name Summary
completionCandidates Optional set of strings to use when the user invokes shell autocomplete on a value for this option.val completionCandidates:CompletionCandidates
completionCandidatesWithDefault val completionCandidatesWithDefault:ValueWithDefault<CompletionCandidates>
envvar The environment variable name to use.val envvar:String?
groupName The name of the group, or null if this option should not be grouped in the help output.var groupName:String?
helpTags Extra information about this option to pass to the help formatter.val helpTags:Map<String,String>
hidden If true, this option should not appear in help output.val hidden:Boolean
metavarWithDefault The metavar to use. Specified at option creation.val metavarWithDefault:ValueWithDefault<Context.() ->String?>
names The names that can be used to invoke this option. They must start with a punctuation character.var names:Set<String>
nvalues The number of values that must be given to this option.val nvalues:Int
optionHelp The description of this option, usually a single line.val optionHelp:String
parameterGroup The group that this option belongs to, or null. Set by the group.var parameterGroup:ParameterGroup?
parser The parser for this option’s values.val parser:OptionWithValuesParser
secondaryNames Names that can be used for a secondary purpose, like disabling flag options.val secondaryNames:Set<String>
transformAll Called in finalize to transform all invocations into the final value.val transformAll:CallsTransformer<EachT, AllT>
transformEach Called in finalize to transform each invocation.val transformEach:ArgsTransformer<ValueT, EachT>
transformValidator Called after all parameters have been finalized to validate the output of transformAllval transformValidator:OptionValidator<AllT>
transformValue Called in finalize to transform each value provided to each invocation.val transformValue:ValueTransformer<ValueT>
value The value for this option.var value: AllT
valueSourceKey Optional explicit key to use when looking this option up from a ValueSourceval valueSourceKey:String?
valueSplit The pattern to split values from the command line on. By default, values are split on whitespace.val valueSplit:Regex?

Functions

Name Summary
copy Create a new option that is a copy of this one with different 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 the same transforms.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>
finalize Called after this command’s argv is parsed to transform and store the option’s value.fun finalize(context:Context, invocations:List<Invocation>):Unit
metavar A name representing the values for this option that can be displayed to the user.fun metavar(context:Context):String?
postValidate Called after all of a command’s parameters have been finalized to perform validation of the final value.fun postValidate(context:Context):Unit
provideDelegate Implementations must call ParameterHolder.registerOptionoperator fun provideDelegate(thisRef:ParameterHolder, prop:KProperty<*>):ReadOnlyProperty<ParameterHolder, AllT>

Extension Functions

Name Summary
associate Change this option to take multiple values, each split on a delimiter, and converted to a map.funRawOption.associate(delimiter:String= "="):OptionWithValues<Map<String,String>,Pair<String,String>,Pair<String,String>>
check Check the final option value and raise an error if it’s not valid.fun <AllT :Any, EachT, ValueT>OptionWithValues<AllT, EachT, ValueT>.check(message:String, validator: (AllT) ->Boolean):OptionDelegate<AllT>
Check the final argument value and raise an error if it’s not valid.fun <AllT :Any, EachT, ValueT>OptionWithValues<AllT, EachT, ValueT>.check(lazyMessage: (AllT) ->String= { it.toString() }, validator: (AllT) ->Boolean):OptionDelegate<AllT>
choice Convert the option based on a fixed set of values.fun <T :Any>RawOption.choice(choices:Map<String, T>, metavar:String= mvar(choices.keys), ignoreCase:Boolean= false):NullableOption<T, T>
fun <T :Any>RawOption.choice(vararg choices:Pair<String, T>, metavar:String= mvar(choices.map { it.first }), ignoreCase:Boolean= false):NullableOption<T, T>
Restrict the option to a fixed set of values.funRawOption.choice(vararg choices:String, metavar:String= mvar(choices.asIterable()), ignoreCase:Boolean= false):NullableOption<String,String>
convert Convert the option’s value type.fun <InT :Any, ValueT :Any>NullableOption<InT, InT>.convert(metavar:String, completionCandidates:CompletionCandidates= completionCandidatesWithDefault.default, conversion:ValueConverter<InT, ValueT>):NullableOption<ValueT, ValueT>
fun <InT :Any, ValueT :Any>NullableOption<InT, InT>.convert(metavar:Context.() ->String= { localization.defaultMetavar() }, completionCandidates:CompletionCandidates= completionCandidatesWithDefault.default, conversion:ValueConverter<InT, ValueT>):NullableOption<ValueT, ValueT>
counted Turn an option into a flag that counts the number of times the option occurs on the command line.funRawOption.counted():FlagOption<Int>
default If the option is not called on the command line (and is not set in an envvar), use value for the option.fun <EachT :Any, ValueT>NullableOption<EachT, ValueT>.default(value: EachT, defaultForHelp:String= value.toString()):OptionWithValues<EachT, EachT, ValueT>
defaultLazy 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.fun <EachT :Any, ValueT>NullableOption<EachT, ValueT>.defaultLazy(defaultForHelp:String= "", value: () -> EachT):OptionWithValues<EachT, EachT, ValueT>
defaultStdin Use - as the default value for an inputStream option.funNullableOption<InputStream,InputStream>.defaultStdin():OptionWithValues<InputStream,InputStream,InputStream>
defaultStdout Use - as the default value for an outputStream option.funNullableOption<OutputStream,OutputStream>.defaultStdout():OptionWithValues<OutputStream,OutputStream,OutputStream>
deprecated Mark this option as deprecated in the help output.fun <AllT, EachT, ValueT>OptionWithValues<AllT, EachT, ValueT>.deprecated(message:String? = "", tagName:String? = "deprecated", tagValue:String= "", error:Boolean= false):OptionDelegate<AllT>
double Convert the option values to a Double``funRawOption.double():NullableOption<Double,Double>
enum Convert the option to the values of an enum.fun <T :Enum<T>>RawOption.enum(ignoreCase:Boolean= true, key: (T) ->String= { it.name }):NullableOption<T, T>
file Convert the option to a File.funRawOption.file(mustExist:Boolean= false, canBeFile:Boolean= true, canBeDir:Boolean= true, mustBeWritable:Boolean= false, mustBeReadable:Boolean= false, canBeSymlink:Boolean= true):NullableOption<File,File>
flag Turn an option into a boolean flag.funRawOption.flag(vararg secondaryNames:String, default:Boolean= false, defaultForHelp:String= ""):FlagOption<Boolean>
float Convert the option values to a Float``funRawOption.float():NullableOption<Float,Float>
groupChoice Convert the option to an option group based on a fixed set of values.fun <T :OptionGroup>RawOption.groupChoice(choices:Map<String, T>):ChoiceGroup<T, T?>
fun <T :OptionGroup>RawOption.groupChoice(vararg choices:Pair<String, T>):ChoiceGroup<T, T?>
groupSwitch Convert the option into a set of flags that each map to an option group.fun <T :OptionGroup>RawOption.groupSwitch(choices:Map<String, T>):ChoiceGroup<T, T?>
fun <T :OptionGroup>RawOption.groupSwitch(vararg choices:Pair<String, T>):ChoiceGroup<T, T?>
help Set the help for this option.fun <AllT, EachT, ValueT>OptionWithValues<AllT, EachT, ValueT>.help(help:String):OptionWithValues<AllT, EachT, ValueT>
inputStream Convert the option to an InputStream.funRawOption.inputStream(fileSystem: FileSystem = FileSystems.getDefault()):NullableOption<InputStream,InputStream>
int Convert the option values to an Int``funRawOption.int():NullableOption<Int,Int>
long Convert the option values to a Long``funRawOption.long():NullableOption<Long,Long>
multiple Make the option return a list of calls; each item in the list is the value of one call.fun <EachT :Any, ValueT>NullableOption<EachT, ValueT>.multiple(default:List<EachT> = emptyList(), required:Boolean= false):OptionWithValues<List<EachT>, EachT, ValueT>
outputStream Convert the option to an OutputStream.funRawOption.outputStream(createIfNotExist:Boolean= true, truncateExisting:Boolean= false, fileSystem: FileSystem = FileSystems.getDefault()):NullableOption<OutputStream,OutputStream>
pair Change this option to take two values, held in a Pair.fun <EachT :Any, ValueT>NullableOption<EachT, ValueT>.pair():NullableOption<Pair<ValueT, ValueT>, ValueT>
path Convert the option to a Path.funRawOption.path(mustExist:Boolean= false, canBeFile:Boolean= true, canBeDir:Boolean= true, mustBeWritable:Boolean= false, mustBeReadable:Boolean= false, canBeSymlink:Boolean= true, fileSystem: FileSystem = FileSystems.getDefault()):NullableOption<Path, Path>
prompt If the option isn’t given on the command line, prompt the user for manual input.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>
required If the option is not called on the command line (and is not set in an envvar), throw a MissingOption.fun <EachT :Any, ValueT>NullableOption<EachT, ValueT>.required():OptionWithValues<EachT, EachT, ValueT>
restrictTo Restrict the option values to fit into a range.fun <T :Comparable<T>>OptionWithValues<T?, T, T>.restrictTo(min: T? = null, max: T? = null, clamp:Boolean= false):OptionWithValues<T?, T, T>
fun <T :Comparable<T>>OptionWithValues<T?, T, T>.restrictTo(range:ClosedRange<T>, clamp:Boolean= false):OptionWithValues<T?, T, T>
split Change to option to take any number of values, separated by a regex.fun <EachT :Any, ValueT>NullableOption<EachT, ValueT>.split(regex:Regex):OptionWithValues<List<ValueT>?,List<ValueT>, ValueT>
Change to option to take any number of values, separated by a string delimiter.fun <EachT :Any, ValueT>NullableOption<EachT, ValueT>.split(delimiter:String):OptionWithValues<List<ValueT>?,List<ValueT>, ValueT>
splitPair Split this option’s value into two with a delimiter.funRawOption.splitPair(delimiter:String= "="):NullableOption<Pair<String,String>,Pair<String,String>>
switch Turn an option into a set of flags that each map to a value.fun <T :Any>RawOption.switch(choices:Map<String, T>):FlagOption<T?>
fun <T :Any>RawOption.switch(vararg choices:Pair<String, T>):FlagOption<T?>
toMap Convert this option’s values from a list of pairs into a map with key-value pairs from the list.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>>
transformAll Transform all calls to the option to the final option type.fun <AllT, EachT :Any, ValueT>NullableOption<EachT, ValueT>.transformAll(defaultForHelp:String? = this.helpTags[HelpFormatter.Tags.DEFAULT], showAsRequired:Boolean= HelpFormatter.Tags.REQUIRED in this.helpTags, transform:CallsTransformer<EachT, AllT>):OptionWithValues<AllT, EachT, ValueT>
transformValues Change the number of values that this option takes.fun <EachInT :Any, EachOutT :Any, ValueT>NullableOption<EachInT, ValueT>.transformValues(nvalues:Int, transform:ArgsTransformer<ValueT, EachOutT>):NullableOption<EachOutT, ValueT>
triple Change this option to take three values, held in a Triple.fun <EachT :Any, ValueT>NullableOption<EachT, ValueT>.triple():NullableOption<Triple<ValueT, ValueT, ValueT>, ValueT>
unique Make the multiple option return a unique set of callsfun <EachT :Any, ValueT>OptionWithValues<List<EachT>, EachT, ValueT>.unique():OptionWithValues<Set<EachT>, EachT, ValueT>
validate Check the final option value and raise an error if it’s not valid.fun <AllT :Any, EachT, ValueT>OptionWithValues<AllT, EachT, ValueT>.validate(validator:OptionValidator<AllT>):OptionDelegate<AllT>