diff --git a/integration/client-cli/client-registration-cli/src/main/java/org/keycloak/client/registration/cli/aesh/AeshConsoleCallbackImpl.java b/integration/client-cli/client-registration-cli/src/main/java/org/keycloak/client/registration/cli/aesh/AeshConsoleCallbackImpl.java index 8235f69dba..608c26d0e1 100644 --- a/integration/client-cli/client-registration-cli/src/main/java/org/keycloak/client/registration/cli/aesh/AeshConsoleCallbackImpl.java +++ b/integration/client-cli/client-registration-cli/src/main/java/org/keycloak/client/registration/cli/aesh/AeshConsoleCallbackImpl.java @@ -47,6 +47,10 @@ class AeshConsoleCallbackImpl extends AeshConsoleCallback { else if(resultHandler != null) resultHandler.onFailure(result); + if (result == CommandResult.FAILURE) { + // we assume the command has already output any error messages + System.exit(1); + } } catch (Exception e) { console.stop(); diff --git a/integration/client-cli/client-registration-cli/src/main/java/org/keycloak/client/registration/cli/commands/KcRegCmd.java b/integration/client-cli/client-registration-cli/src/main/java/org/keycloak/client/registration/cli/commands/KcRegCmd.java index 3b513421f3..a166303871 100644 --- a/integration/client-cli/client-registration-cli/src/main/java/org/keycloak/client/registration/cli/commands/KcRegCmd.java +++ b/integration/client-cli/client-registration-cli/src/main/java/org/keycloak/client/registration/cli/commands/KcRegCmd.java @@ -20,12 +20,12 @@ import org.jboss.aesh.cl.GroupCommandDefinition; import org.jboss.aesh.console.command.CommandException; import org.jboss.aesh.console.command.CommandResult; import org.jboss.aesh.console.command.invocation.CommandInvocation; -import org.keycloak.client.registration.cli.util.IoUtil; import java.io.PrintWriter; import java.io.StringWriter; import static org.keycloak.client.registration.cli.util.ConfigUtil.DEFAULT_CONFIG_FILE_STRING; +import static org.keycloak.client.registration.cli.util.IoUtil.printOut; import static org.keycloak.client.registration.cli.util.OsUtil.CMD; import static org.keycloak.client.registration.cli.util.OsUtil.PROMPT; @@ -43,9 +43,14 @@ public class KcRegCmd extends AbstractGlobalOptionsCmd { @Override public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { try { - IoUtil.printOut(usage()); - - return CommandResult.SUCCESS; + // if --help was requested then status is SUCCESS + // if not we print help anyway, but status is FAILURE + if (printHelp()) { + return CommandResult.SUCCESS; + } else { + printOut(usage()); + return CommandResult.FAILURE; + } } finally { commandInvocation.stop(); } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/registration/KcRegTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/registration/KcRegTest.java index 2469880f80..ae80a94d34 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/registration/KcRegTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/registration/KcRegTest.java @@ -33,7 +33,7 @@ public class KcRegTest extends AbstractCliTest { */ KcRegExec exe = execute(""); - Assert.assertEquals("exitCode == 0", 0, exe.exitCode()); + Assert.assertEquals("exitCode", 1, exe.exitCode()); List lines = exe.stdoutLines(); Assert.assertTrue("stdout output not empty", lines.size() > 0);