diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java index cbf026e57ac3..bdf7f06080fe 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java @@ -101,16 +101,11 @@ private static class IncludeOptions { } private ExecutionExceptionHandler errorHandler = new ExecutionExceptionHandler(); + private List uncrecognizedArgs = new ArrayList<>(); public void parseAndRun(List cliArgs) { // perform two passes over the cli args. First without option validation to determine the current command, then with option validation enabled - CommandLine cmd = createCommandLine(spec -> spec - .addUnmatchedArgsBinding(CommandLine.Model.UnmatchedArgsBinding.forStringArrayConsumer(new ISetter() { - @Override - public T set(T value) throws Exception { - return null; // just ignore - } - }))); + CommandLine cmd = createCommandLine(spec -> {}).setUnmatchedArgumentsAllowed(true); String[] argArray = cliArgs.toArray(new String[0]); try { @@ -157,6 +152,16 @@ private CommandLine createCommandLineForCommand(List cliArgs, List T set(T value) { + if (value != null) { + uncrecognizedArgs.addAll(Arrays.asList((String[]) value)); + } + return null; // doesn't matter + } + })); + addHelp(currentSpec); } @@ -324,6 +329,10 @@ private static boolean wasBuildEverRun() { * @param abstractCommand */ public void validateConfig(List cliArgs, AbstractCommand abstractCommand) { + if (!uncrecognizedArgs.isEmpty()) { + throw new KcUnmatchedArgumentException(abstractCommand.getCommandLine().orElseThrow(), uncrecognizedArgs); + } + if (cliArgs.contains(OPTIMIZED_BUILD_OPTION_LONG) && !wasBuildEverRun()) { throw new PropertyException(Messages.optimizedUsedForFirstStartup()); }