Skip to content

Commit cdb0441

Browse files
authored
#595 Added overloads for choice type to accept list (#596)
Fixes #595
1 parent 3d8a842 commit cdb0441

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

clikt/api/clikt.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,15 +1261,19 @@ public final class com/github/ajalt/clikt/parameters/types/BooleanKt {
12611261
}
12621262

12631263
public final class com/github/ajalt/clikt/parameters/types/ChoiceKt {
1264+
public static final fun choice (Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;Ljava/lang/Iterable;Z)Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;
12641265
public static final fun choice (Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;Ljava/util/Map;Z)Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;
12651266
public static final fun choice (Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;[Ljava/lang/String;Z)Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;
12661267
public static final fun choice (Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;[Lkotlin/Pair;Z)Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;
1268+
public static final fun choice (Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;Ljava/lang/Iterable;Ljava/lang/String;Z)Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;
12671269
public static final fun choice (Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;Ljava/util/Map;Ljava/lang/String;Z)Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;
12681270
public static final fun choice (Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;[Ljava/lang/String;Ljava/lang/String;Z)Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;
12691271
public static final fun choice (Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;[Lkotlin/Pair;Ljava/lang/String;Z)Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;
1272+
public static synthetic fun choice$default (Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;Ljava/lang/Iterable;ZILjava/lang/Object;)Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;
12701273
public static synthetic fun choice$default (Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;Ljava/util/Map;ZILjava/lang/Object;)Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;
12711274
public static synthetic fun choice$default (Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;[Ljava/lang/String;ZILjava/lang/Object;)Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;
12721275
public static synthetic fun choice$default (Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;[Lkotlin/Pair;ZILjava/lang/Object;)Lcom/github/ajalt/clikt/parameters/arguments/ProcessedArgument;
1276+
public static synthetic fun choice$default (Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;Ljava/lang/Iterable;Ljava/lang/String;ZILjava/lang/Object;)Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;
12731277
public static synthetic fun choice$default (Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;Ljava/util/Map;Ljava/lang/String;ZILjava/lang/Object;)Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;
12741278
public static synthetic fun choice$default (Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;[Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;
12751279
public static synthetic fun choice$default (Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;[Lkotlin/Pair;Ljava/lang/String;ZILjava/lang/Object;)Lcom/github/ajalt/clikt/parameters/options/OptionWithValues;

clikt/src/commonMain/kotlin/com/github/ajalt/clikt/parameters/types/choice.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ fun RawArgument.choice(
7878
return choice(choices.associateBy { it }, ignoreCase)
7979
}
8080

81+
82+
/**
83+
* Restrict the argument to a fixed set of values.
84+
*
85+
* If [ignoreCase] is `true`, the argument will accept values as any mix of upper and lower case.
86+
* The argument's final value will always match the case of the corresponding value in [choices].
87+
*
88+
* ### Example:
89+
*
90+
* ```
91+
* argument().choice(listOf("foo", "bar"))
92+
* ```
93+
*/
94+
fun RawArgument.choice(
95+
choices: Iterable<String>,
96+
ignoreCase: Boolean = false,
97+
): ProcessedArgument<String, String> {
98+
return choice(choices.associateBy { it }, ignoreCase)
99+
}
100+
81101
// options
82102

83103
/**
@@ -145,3 +165,23 @@ fun RawOption.choice(
145165
): NullableOption<String, String> {
146166
return choice(choices.associateBy { it }, metavar, ignoreCase)
147167
}
168+
169+
/**
170+
* Restrict the option to a fixed set of values.
171+
*
172+
* If [ignoreCase] is `true`, the option will accept values as any mix of upper and lower case.
173+
* The option's final value will always match the case of the corresponding value in [choices].
174+
*
175+
* ### Example:
176+
*
177+
* ```
178+
* option().choice(listOf("foo", "bar"))
179+
* ```
180+
*/
181+
fun RawOption.choice(
182+
choices: Iterable<String>,
183+
metavar: String = mvar(choices.asIterable()),
184+
ignoreCase: Boolean = false,
185+
): NullableOption<String, String> {
186+
return choice(choices.associateBy { it }, metavar, ignoreCase)
187+
}

0 commit comments

Comments
 (0)