Hi, now interactive mode hide text digitized by user. There is a mode to use interactive mode which show text that user insert during write on console?
Currently the picocli library does not provide this functionality, but I think it would be a good feature to have.
Perhaps we should add an echo attribute, that allows applications to control whether the user input is echo-ed to the console or not. I'm also thinking to add a prompt attribute so that applications can customize the text displayed to the end user for an interactive option. For example:
@Option(names = "-x", interactive = true, echo = true, prompt = "Enter your PIN: ")
String pin;
Note that you can work around this in the application, by calling Console.readLine:
public class Interactive implements Runnable {
@Option(names = {"-u", "--user"}, interactive = true,
description = "user id")
private String user;
public void run() {
if (user == null) {
user = new String(System.console().readLine("We really need a user id: "));
}
System.out.printf("Ok, we got: %s%n", user);
// do stuff...
}
public static void main(String[] args) {
int exitCode = new CommandLine(new Interactive()).execute(args);
}
}
Note that you can work around this in the application, by calling
Console.readLine:public class Interactive implements Runnable { @Option(names = {"-u", "--user"}, interactive = true, description = "user id") private String user; public void run() { if (user == null) { user = new String(System.console().readLine("We really need a user id: ")); } System.out.printf("Ok, we got: %s%n", user); // do stuff... } public static void main(String[] args) { int exitCode = new CommandLine(new Interactive()).execute(args); } }
Then, the interactive flag is useless in this case and can be dropped, right?
@xinchao-zhang Yes, I think you are correct.
@remkop Hi, I'm interested in echo and prompt feature. Can I try to create a PR?
Yes, great!
Most helpful comment
Note that you can work around this in the application, by calling
Console.readLine: