You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
}
The text was updated successfully, but these errors were encountered:
Seems like the obvious choice. Completely new to picocli, so not immediately clear what the difference between the result of cmd.execute() vs. cmd.getParseResult(). But one or the other would make sense.
BTW, picocli is great. I had build a poor man's shell and command parser, and have been refactoring over the last week, with much delight.
Seems like the obvious choice. Completely new to picocli, so not immediately clear what the difference between the result of cmd.execute() vs. cmd.getParseResult(). But one or the other would make sense.
The cmd.execute() method returns an exit code, whereas cmd.getParseResult returns an object with data built up by the parser. This is the richest information possible to return. Other values may be derived from the ParseResult. So it seems best to return ParseResult.
BTW, picocli is great. I had build a poor man's shell and command parser, and have been refactoring over the last week, with much delight.
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
PicocliCommands source in question:
The text was updated successfully, but these errors were encountered: