Skip to content

Commit d693d08

Browse files
committed
Update docs
1 parent 4543cb7 commit d693d08

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

docs/arguments.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ functions like [`pair`][pair] and [`triple`][triple]. Unlike options, arguments
5656
variable (or unlimited) number of values. This is common with file path arguments, since
5757
they are frequently expanded with a glob pattern on the command line.
5858

59-
You can declare any number of arguments with fixed numbers of values,
60-
but only one variadic argument.
59+
Variadic arguments are declared with [`multiple`][multiple]. You can declare any number of arguments
60+
with fixed numbers of values, but only one variadic argument in a command.
6161

6262
```kotlin tab="Example"
6363
class Copy : CliktCommand() {
64-
val source by argument().path(mustExist = true).multiple()
65-
val dest by argument().path(canBeFile = false)
64+
val source: List<Path> by argument().path(mustExist = true).multiple()
65+
val dest: Path by argument().path(canBeFile = false)
6666
override fun run() {
6767
echo("Copying files $source to $dest")
6868
}
@@ -74,6 +74,12 @@ $ ./copy file.* out/
7474
Copying files [file.txt, file.md] to out/
7575
```
7676

77+
You can also use [`unique`][unique] to discard duplicates:
78+
79+
```kotlin
80+
val source: Set<Path> by argument().path(mustExist = true).multiple().unique()
81+
```
82+
7783
## Option-Like Arguments (Using `--`)
7884

7985
Clikt normally parses any value that starts with punctuation as an
@@ -114,3 +120,5 @@ bar.txt
114120
[argument]: api/clikt/com.github.ajalt.clikt.parameters.arguments/argument.md
115121
[pair]: api/clikt/com.github.ajalt.clikt.parameters.arguments/pair.md
116122
[triple]: api/clikt/com.github.ajalt.clikt.parameters.arguments/triple.md
123+
[unique]: api/clikt/com.github.ajalt.clikt.parameters.arguments/unique.md
124+
[multiple]: api/clikt/com.github.ajalt.clikt.parameters.arguments/multiple.md

docs/options.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ is never given, the list will be empty (or you can specify a default to use).
210210

211211
```kotlin tab="Example"
212212
class Commit : CliktCommand() {
213-
val message by option("-m").multiple()
213+
val message: List<String> by option("-m").multiple()
214214
override fun run() {
215215
echo(message.joinToString("\n"))
216216
}
@@ -224,22 +224,41 @@ bar
224224
```
225225

226226
You can combine [`multiple`][multiple] with item type conversions and multiple values.
227-
For example:
228227

229228
```kotlin
230229
val opt: List<Pair<Int, Int>> by option().int().pair().multiple()
231230
```
232231

232+
### Default values for option().multiple()
233+
233234
You can also supply a default value to [`multiple`][multiple] or require at least one value be present
234235
on the command line. These are specified as arguments rather than with separate extension functions
235236
since they don't change the type of the delegate.
236237

237238
```kotlin tab="Required"
238-
val opt by option().multiple(required=true)
239+
val opt: List<String> by option().multiple(required=true)
239240
```
240241

241242
```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]
243262
```
244263

245264
## Boolean Flag Options
@@ -918,6 +937,7 @@ val opt: Pair<Int, Int> by option("-o", "--opt")
918937
[transformValues]: api/clikt/com.github.ajalt.clikt.parameters.options/transform-values.md
919938
[default]: api/clikt/com.github.ajalt.clikt.parameters.options/default.md
920939
[multiple]: api/clikt/com.github.ajalt.clikt.parameters.options/multiple.md
940+
[unique]: api/clikt/com.github.ajalt.clikt.parameters.options/unique.md
921941
[defaultLazy]: api/clikt/com.github.ajalt.clikt.parameters.options/default-lazy.md
922942
[split]: api/clikt/com.github.ajalt.clikt.parameters.options/split.md
923943
[flag]: api/clikt/com.github.ajalt.clikt.parameters.options/flag.md

0 commit comments

Comments
 (0)