use of org.springframework.boot.cli.command.status.ExitStatus in project spring-boot by spring-projects.
the class CommandRunner method runAndHandleErrors.
/**
* Run the appropriate and handle and errors.
* @param args the input arguments
* @return a return status code (non boot is used to indicate an error)
*/
public int runAndHandleErrors(String... args) {
String[] argsWithoutDebugFlags = removeDebugFlags(args);
boolean debug = argsWithoutDebugFlags.length != args.length;
if (debug) {
System.setProperty("debug", "true");
}
try {
ExitStatus result = run(argsWithoutDebugFlags);
// The caller will hang up if it gets a non-zero status
if (result != null && result.isHangup()) {
return (result.getCode() > 0) ? result.getCode() : 0;
}
return 0;
} catch (NoArgumentsException ex) {
showUsage();
return 1;
} catch (Exception ex) {
return handleError(debug, ex);
}
}
use of org.springframework.boot.cli.command.status.ExitStatus in project spring-boot by spring-projects.
the class EncodePasswordCommandTests method encodeWithUnknownAlgorithmShouldExitWithError.
@Test
void encodeWithUnknownAlgorithmShouldExitWithError() throws Exception {
EncodePasswordCommand command = new EncodePasswordCommand();
ExitStatus status = command.run("--algorithm", "bad", "boot");
then(this.log).should().error("Unknown algorithm, valid options are: default,bcrypt,pbkdf2");
assertThat(status).isEqualTo(ExitStatus.ERROR);
}
use of org.springframework.boot.cli.command.status.ExitStatus in project spring-boot by spring-projects.
the class EncodePasswordCommandTests method encodeWithNoAlgorithmShouldUseBcrypt.
@Test
void encodeWithNoAlgorithmShouldUseBcrypt() throws Exception {
EncodePasswordCommand command = new EncodePasswordCommand();
ExitStatus status = command.run("boot");
then(this.log).should().info(this.message.capture());
assertThat(this.message.getValue()).startsWith("{bcrypt}");
assertThat(PasswordEncoderFactories.createDelegatingPasswordEncoder().matches("boot", this.message.getValue())).isTrue();
assertThat(status).isEqualTo(ExitStatus.OK);
}
use of org.springframework.boot.cli.command.status.ExitStatus in project spring-boot by spring-projects.
the class EncodePasswordCommandTests method encodeWithBCryptShouldUseBCrypt.
@Test
void encodeWithBCryptShouldUseBCrypt() throws Exception {
EncodePasswordCommand command = new EncodePasswordCommand();
ExitStatus status = command.run("-a", "bcrypt", "boot");
then(this.log).should().info(this.message.capture());
assertThat(this.message.getValue()).doesNotStartWith("{");
assertThat(new BCryptPasswordEncoder().matches("boot", this.message.getValue())).isTrue();
assertThat(status).isEqualTo(ExitStatus.OK);
}
use of org.springframework.boot.cli.command.status.ExitStatus in project spring-boot by spring-projects.
the class RunProcessCommand method run.
protected ExitStatus run(Collection<String> args) throws IOException {
this.process = new RunProcess(this.command);
int code = this.process.run(true, StringUtils.toStringArray(args));
if (code == 0) {
return ExitStatus.OK;
} else {
return new ExitStatus(code, "EXTERNAL_ERROR");
}
}
Aggregations