Add support for exit codes

- New configurations to CommandRegistration
- Re-using exit code concepts from boot
- Handling exit codes only in non-interactive mode
- Adding e2e commands and tests for better coverage
- Fixes #431
This commit is contained in:
Janne Valkealahti
2022-05-30 21:26:11 +01:00
parent 08428c88cb
commit 3891a8b375
16 changed files with 707 additions and 20 deletions

View File

@@ -106,4 +106,41 @@ public class E2ECommands {
.build();
}
@Bean
public CommandRegistration testExitCodeRegistration() {
return CommandRegistration.builder()
.command("e2e", "reg", "exit-code")
.group("E2E Commands")
.withOption()
.longNames("arg1")
.required()
.and()
.withTarget()
.consumer(ctx -> {
String arg1 = ctx.getOptionValue("arg1");
throw new MyException(arg1);
})
.and()
.withExitCode()
.map(MyException.class, 3)
.map(t -> {
String msg = t.getMessage();
if (msg != null && msg.contains("ok")) {
return 0;
}
else if (msg != null && msg.contains("fun")) {
return 4;
}
return 0;
})
.and()
.build();
}
static class MyException extends RuntimeException {
MyException(String msg) {
super(msg);
}
}
}