public class ArgumentKt
Modifier and Type | Method and Description |
---|---|
static ProcessedArgument<java.lang.String,java.lang.String> |
argument(CliktCommand $receiver,
java.lang.String name,
java.lang.String help)
Create a property delegate argument.
|
static <T> ProcessedArgument<T,T> |
convert(ProcessedArgument<java.lang.String,java.lang.String> $receiver,
kotlin.jvm.functions.Function2<? super com.github.ajalt.clikt.parameters.arguments.ArgumentTransformContext,? super java.lang.String,? extends T> conversion)
Convert the argument's values.
|
static <T> ArgumentDelegate<T> |
default(ProcessedArgument<T,T> $receiver,
T value)
If the argument is not given, use value instead of throwing an error.
|
static <T> ProcessedArgument<java.util.List,T> |
multiple(ProcessedArgument<T,T> $receiver,
boolean required)
Accept any number of values to this argument.
|
static <AllT,ValueT> |
nullableValidate(ProcessedArgument<AllT,ValueT> $receiver,
kotlin.jvm.functions.Function2<? super com.github.ajalt.clikt.parameters.arguments.ArgumentTransformContext,? super AllT,kotlin.Unit> validator)
Check the final argument value and raise an error if it's not valid.
|
static <AllT,ValueT> |
optional(ProcessedArgument<AllT,ValueT> $receiver)
Return null instead of throwing an error if no value is given.
|
static <T> ProcessedArgument<kotlin.Pair,T> |
pair(ProcessedArgument<T,T> $receiver)
Require exactly two values to this argument, and store them in a Pair.
|
static <AllInT,ValueT,AllOutT> |
transformAll(ProcessedArgument<AllInT,ValueT> $receiver,
java.lang.Integer nvalues,
java.lang.Boolean required,
kotlin.jvm.functions.Function2<? super com.github.ajalt.clikt.parameters.arguments.ArgumentTransformContext,? super java.util.List<? extends ValueT>,? extends AllOutT> transform)
Transform all values to the final argument type.
|
static <T> ProcessedArgument<kotlin.Triple,T> |
triple(ProcessedArgument<T,T> $receiver)
Require exactly three values to this argument, and store them in a Triple
|
static <AllT,ValueT> |
validate(ProcessedArgument<AllT,ValueT> $receiver,
kotlin.jvm.functions.Function2<? super com.github.ajalt.clikt.parameters.arguments.ArgumentTransformContext,? super AllT,kotlin.Unit> validator)
Check the final argument value and raise an error if it's not valid.
|
public static ProcessedArgument<java.lang.String,java.lang.String> argument(CliktCommand $receiver, java.lang.String name, java.lang.String help)
Create a property delegate argument.
The order that these delegates are created is the order that arguments must appear. By default, the
argument takes one value and throws an error if no value is given. The behavior can be changed with
functions like IntKt.int
and ArgumentKt.optional
.
name
- The metavar for this argument. If not given, the name is inferred form the property name.help
- The description of this argument for help output.IntKt.int
,
ArgumentKt.optional
public static <AllInT,ValueT,AllOutT> ProcessedArgument<AllOutT,ValueT> transformAll(ProcessedArgument<AllInT,ValueT> $receiver, java.lang.Integer nvalues, java.lang.Boolean required, kotlin.jvm.functions.Function2<? super com.github.ajalt.clikt.parameters.arguments.ArgumentTransformContext,? super java.util.List<? extends ValueT>,? extends AllOutT> transform)
Transform all values to the final argument type.
The input is a list of values, one for each value on the command line. The values in the
list are the output of calls to ArgumentKt.convert
. The input list will have a size of nvalues if nvalues is > 0.
Used to implement functions like ArgumentKt.pair
and ArgumentKt.multiple
.
nvalues
- The number of values required by this argument. A negative nvalues indicates a variable number
of values.required
- If true, an error with be thrown if no values are provided to this argument.ArgumentKt.convert
,
ArgumentKt.pair
,
ArgumentKt.multiple
public static <AllT,ValueT> ProcessedArgument<AllT,ValueT> optional(ProcessedArgument<AllT,ValueT> $receiver)
Return null instead of throwing an error if no value is given.
This must be called after all other transforms.
Example:
val arg: Int? by argument().int().optional()
public static <T> ProcessedArgument<java.util.List,T> multiple(ProcessedArgument<T,T> $receiver, boolean required)
Accept any number of values to this argument.
Only one argument in a command may use this function, and the command may not have subcommands. This must be called after all other transforms.
Example:
val arg: List by argument().int().multiple()
public static <T> ProcessedArgument<kotlin.Pair,T> pair(ProcessedArgument<T,T> $receiver)
Require exactly two values to this argument, and store them in a Pair.
This must be called after converting the value type, and before other transforms.
Example:
val arg: Pair by argument().int().pair()
public static <T> ProcessedArgument<kotlin.Triple,T> triple(ProcessedArgument<T,T> $receiver)
Require exactly three values to this argument, and store them in a Triple
This must be called after converting the value type, and before other transforms.
Example:
val arg: Triple by argument().int().triple()
public static <T> ArgumentDelegate<T> default(ProcessedArgument<T,T> $receiver, T value)
If the argument is not given, use value instead of throwing an error.
This must be applied after all other transforms.
Example:
val arg: Pair by argument().int().pair().default(1 to 2)
public static <T> ProcessedArgument<T,T> convert(ProcessedArgument<java.lang.String,java.lang.String> $receiver, kotlin.jvm.functions.Function2<? super com.github.ajalt.clikt.parameters.arguments.ArgumentTransformContext,? super java.lang.String,? extends T> conversion)
Convert the argument's values.
The conversion is called once for each value given. If any errors are thrown, they are caught and a
exception BadParameterValue
is thrown with the error message. You can call fail
to throw a exception BadParameterValue
manually.
public static <AllT,ValueT> ArgumentDelegate<AllT> validate(ProcessedArgument<AllT,ValueT> $receiver, kotlin.jvm.functions.Function2<? super com.github.ajalt.clikt.parameters.arguments.ArgumentTransformContext,? super AllT,kotlin.Unit> validator)
Check the final argument value and raise an error if it's not valid.
The validator is called with the final argument type (the output of OptionWithValuesKt.transformAll
), and should call
fail
if the value is not valid.
You can also call require
to fail automatically if an expression is false.
Example:
val opt by argument().int().validate { require(it % 2 == 0) { "value must be even" } }
OptionWithValuesKt.transformAll
public static <AllT,ValueT> ArgumentDelegate<AllT> nullableValidate(ProcessedArgument<AllT,ValueT> $receiver, kotlin.jvm.functions.Function2<? super com.github.ajalt.clikt.parameters.arguments.ArgumentTransformContext,? super AllT,kotlin.Unit> validator)
Check the final argument value and raise an error if it's not valid.
The validator is called with the final argument type (the output of OptionWithValuesKt.transformAll
), and should call
fail
if the value is not valid. It is not called if the delegate value is null.
You can also call require
to fail automatically if an expression is false.
Example:
val opt by argument().int().validate { require(it % 2 == 0) { "value must be even" } }
OptionWithValuesKt.transformAll