Skip to content

Defining a CLI

Declare parameters

1
2
3
4
5
@Parameters(index = "0", description = ["Name to greet"])
lateinit var name: String

@Parameters(index = "1", arity = "0..*", description = ["Additional files"])
lateinit var additional: List<Path>

Run like this: ./my-script a b c and name will be a, additional will be [b, c].

Declare named options

1
2
3
4
5
6
@Option(names = ["--config", "-c"], description = ["Config file."])
lateinit var someFile: Path

// Primitive types (booleans, numbers) shouldn't use 'lateinit'.
@Option(names = ["--toggle"])
var toggle: Boolean = false

Description

1
2
3
@file:Description("""
    A short description of what this script does, which will be included in the --help output.
""")

Arguments without using PicoCLI

1
2
@Parameters
lateinit var args: List<String>

More

See PicoCLI.