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

User guide, chapter 3.2.3. Forcing Interactive Input: code sample: add Kotlin version #1627

Merged
merged 1 commit into from
Mar 7, 2022
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
19 changes: 19 additions & 0 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,25 @@ public class Main implements Runnable {
}
----

.Kotlin
[source,kotlin,role="secondary"]
----
@Command
class Main : Runnable {
@Option(names = ["--interactive"], description = ["unattended run"], interactive = true)
var value: String? = null
override fun run() {
if (value == null && System.console() != null) {
// alternatively, use console::readPassword
value = System.console().readLine("Enter value for --interactive: ")
}
println("You provided value '$value'")
}
}

fun main(args: Array<String>) : Unit = exitProcess(CommandLine(Main()).execute(*args))
----

=== Short (POSIX) Options
Picocli supports http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02[POSIX clustered short options]:
one or more single-character options without option-arguments, followed by at most one option with an option-argument, can be grouped behind one '-' delimiter.
Expand Down