Defining a CLI
Declare parameters
| @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
| @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
| @file:Description("""
A short description of what this script does, which will be included in the --help output.
""")
|
Arguments without using PicoCLI
| @Parameters
lateinit var args: List<String>
|
More
See PicoCLI.