-
Notifications
You must be signed in to change notification settings - Fork 441
Closed
Labels
theme: shellAn issue or change related to interactive (JLine) applicationsAn issue or change related to interactive (JLine) applicationstype: bug 🐛
Milestone
Description
- Version 4.7.6
- File: PicocliCommands.java
- Class: picocli.shell.jline3.PicocliCommands extends CommandRegistry
I started with the Picocli/Jline3 example to implement a shell.
invoke
always returns null, and discards the command result. Is this a bug or feature? If a "feature" how best to signal a command loop to quit? (Other than end of file?)
My code, based on the example, looks like this
// COMMAND LOOP
while (true) {
try {
systemRegistry.cleanUp();
line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null);
Object result = systemRegistry.execute(line);
// Oops, result is always null, this will not work
if (result instanceof Integer && ((Integer) result) < 0) {
// terminate loop
return;
}
} catch {
....
}
...
// COMMAND
@Command(name = "quit", mixinStandardHelpOptions = true)
static class QuitCommand implements Callable<Integer> {
public Integer call() {
System.out.println("Bye now.");
return -1; // signals termination of the command loop
}
}
PicocliCommands source in question:
// For JLine >= 3.16.0
@Override
public Object invoke(CommandRegistry.CommandSession session, String command, Object... args) throws Exception {
List<String> arguments = new ArrayList<>();
arguments.add( command );
arguments.addAll( Arrays.stream( args ).map( Object::toString ).collect( Collectors.toList() ) );
cmd.execute( arguments.toArray( new String[0] ) ); // <<<<<<<<<<<<< execute result is discarded
return null; // <<<<<<<<<<<<< always returns null
}
Metadata
Metadata
Assignees
Labels
theme: shellAn issue or change related to interactive (JLine) applicationsAn issue or change related to interactive (JLine) applicationstype: bug 🐛