@@ -210,7 +210,7 @@ is never given, the list will be empty (or you can specify a default to use).
210
210
211
211
``` kotlin tab="Example"
212
212
class Commit : CliktCommand () {
213
- val message by option(" -m" ).multiple()
213
+ val message: List < String > by option(" -m" ).multiple()
214
214
override fun run () {
215
215
echo(message.joinToString(" \n " ))
216
216
}
@@ -224,22 +224,41 @@ bar
224
224
```
225
225
226
226
You can combine [ ` multiple ` ] [ multiple ] with item type conversions and multiple values.
227
- For example:
228
227
229
228
``` kotlin
230
229
val opt: List <Pair <Int , Int >> by option().int().pair().multiple()
231
230
```
232
231
232
+ ### Default values for option().multiple()
233
+
233
234
You can also supply a default value to [ ` multiple ` ] [ multiple ] or require at least one value be present
234
235
on the command line. These are specified as arguments rather than with separate extension functions
235
236
since they don't change the type of the delegate.
236
237
237
238
``` kotlin tab="Required"
238
- val opt by option().multiple(required= true )
239
+ val opt: List < String > by option().multiple(required= true )
239
240
```
240
241
241
242
``` kotlin tab="Default"
242
- val opt by option().multiple(default= listOf (" default message" ))
243
+ val opt: List <String > by option().multiple(default= listOf (" default message" ))
244
+ ```
245
+
246
+ ### Deduplicating option().multiple() into a unique set
247
+
248
+ You can discard duplicate values from a ` multiple ` option with [ ` unique ` ] [ unique ] .
249
+
250
+ ``` kotlin tab="Example"
251
+ class Build : CliktCommand () {
252
+ val platforms: Set <String > by option(" -p" ).multiple().unique()
253
+ override fun run () {
254
+ echo(" Building for platforms: $platforms " )
255
+ }
256
+ }
257
+ ```
258
+
259
+ ``` text tab="Usage"
260
+ $ ./build -p android -p ios -p android
261
+ Building for platforms: [android, ios]
243
262
```
244
263
245
264
## Boolean Flag Options
@@ -918,6 +937,7 @@ val opt: Pair<Int, Int> by option("-o", "--opt")
918
937
[ transformValues ] : api/clikt/com.github.ajalt.clikt.parameters.options/transform-values.md
919
938
[ default ] : api/clikt/com.github.ajalt.clikt.parameters.options/default.md
920
939
[ multiple ] : api/clikt/com.github.ajalt.clikt.parameters.options/multiple.md
940
+ [ unique ] : api/clikt/com.github.ajalt.clikt.parameters.options/unique.md
921
941
[ defaultLazy ] : api/clikt/com.github.ajalt.clikt.parameters.options/default-lazy.md
922
942
[ split ] : api/clikt/com.github.ajalt.clikt.parameters.options/split.md
923
943
[ flag ] : api/clikt/com.github.ajalt.clikt.parameters.options/flag.md
0 commit comments