Descripción
Create a Picocli command with interactive prompts
File Template: ✅
Prefix
picocli:prompt
Scopes
java
Snippet de código
import picocli.CommandLine;
import picocli.CommandLine.Command;
import java.util.Scanner;
@Command(name = "${1:interactive}", mixinStandardHelpOptions = true, description = "${2:Command with user prompts}")
public class ${1:InteractiveCommand} implements Runnable {
@Override
public void run() {
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter your name: ");
String name = scanner.nextLine();
System.out.print("Please enter your age: ");
int age = Integer.parseInt(scanner.nextLine());
System.out.println("Hello " + name + ", you are " + age + " years old!");
scanner.close();
}
public static void main(String[] args) {
int exitCode = new CommandLine(new ${1:InteractiveCommand}()).execute(args);
System.exit(exitCode);
}
}