Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAUTION admonitions, Kotlin code sample #1307

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,30 @@ class SetPositionCommand {
}
----

.Kotlin
[source,kotlin,role="secondary"]
----
@Command(name = "set-position")
class SetPositionCommand {
@Parameters(parameterConsumer = PointConverter::class)
private lateinit var position: Point

class PointConverter : IParameterConsumer {
override fun consumeParameters(args: Stack<String>,
argSpec: ArgSpec,
commandSpec: CommandSpec) {
if (args.size < 2) {
throw ParameterException(commandSpec.commandLine(),
"Missing coordinates for Point. Please specify 2 coordinates.")
}
val x = args.pop().toInt()
val y = args.pop().toInt()
argSpec.setValue(Point(x, y))
}
}
}
----

See the sections on <<Custom Parameter Processing>> for more details.

CAUTION: Make sure any nested classes are `static`, or picocli will not be able to instantiate them without a <<Custom Factory>>.
Expand Down Expand Up @@ -1380,6 +1404,8 @@ This may also be useful for applications that need a custom type converter but w

Type converters declared with the `converter` attribute need to have a public no-argument constructor to be instantiated, unless a <<Custom Factory>> is installed to instantiate classes.

CAUTION: If your type converter is declared as nested class, make sure you mark this class as `static`, or picocli will not be able to instantiate your nested converter class without a <<Custom Factory>>.

=== Arrays, Collections, Maps
NOTE: Starting from picocli 2.0, the `type` attribute is no longer necessary for `Collection` and `Map` fields:
picocli will infer the collection element type from the generic type.
Expand Down Expand Up @@ -7783,7 +7809,7 @@ class App implements Runnable {
description = ["App description"],
footerHeading = "Copyright%n", footer = ["(c) Copyright by the authors"],
showAtFileInUsageHelp = true)
class AppKt : Runnable {
class App : Runnable {
@Option(names = ["-x"]) var x = 0

override fun run() { println("Hello from app!\nx = $x") }
Expand Down Expand Up @@ -10162,6 +10188,7 @@ class Dynamic {

All transformers are called once, after the full command hierarchy is constructed, and before any command line arguments are parsed.

CAUTION: If your model transformer is declared as nested class, make sure you mark this class as `static`, or picocli will not be able to instantiate your transformer class without a <<Custom Factory>>.

=== Automatic Parameter Indexes
==== Automatic Indexes
Expand Down