Open xenoterracide opened 3 years ago
The exit code logic could certainly do with a refresh. We have another issue (#25100) related to the SpringApplication.exit
method.
One trick that might work in the meantime is to put ExitCodeGenerator
on an exception:
@Component
public class MyApplicationRunner implements CommandLineRunner {
private final MyCommand myCommand;
private final IFactory factory; // auto-configured to inject PicocliSpringFactory
public MyApplicationRunner(MyCommand myCommand, IFactory factory) {
this.myCommand = myCommand;
this.factory = factory;
}
@Override
public void run(String... args) throws Exception {
int exitCode = new CommandLine(myCommand, factory).execute(args);
if (exitCode != 0) {
throw new MyExitException(exitCode);
}
}
static class ExitException implements ExitCodeGenerator {
private final int code;
ExitException(int code) {
this.code = code;
}
@Override
public int getExitCode() {
return this.code;
}
}
}
Hello, i would like to solve this issue
Should this interface be implemented only by classes that use exit code or in general? I can't seem to find any example of run codes that use exit code in general
So in order to do a command line runner with an exit code you have to do mutable state (at least from what I can find documented), here's picocli's example
and from what little is in the reference documentation this s true, I think we need an interface that can work without mutability.