From ccc23f43b77b65b28131b22dce18a6ca89359a21 Mon Sep 17 00:00:00 2001 From: Maciej Lisowski Date: Fri, 29 Dec 2023 20:48:00 +0100 Subject: [PATCH] Fix quarkus dev broken for command mode arguments (cherry picked from commit 3c2023760cd9d1505ec9607ed53eec4eba9d17aa) --- .../deployment/console/ConsoleCommand.java | 10 ++++++++++ .../console/ConsoleStateManager.java | 20 +++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleCommand.java b/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleCommand.java index 73eaf0a311231..8c0d56ba3036c 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleCommand.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleCommand.java @@ -39,6 +39,16 @@ public ConsoleCommand(char key, String description, HelpState helpState, Runnabl this(key, description, null, -1, helpState, runnable); } + public static ConsoleCommand duplicateCommandWithNewPromptString(ConsoleCommand commandToDuplicate, + String newPromptString) { + return new ConsoleCommand(commandToDuplicate.getKey(), + commandToDuplicate.getDescription(), + newPromptString, + commandToDuplicate.getPromptPriority(), + commandToDuplicate.getHelpState(), + commandToDuplicate.getReadLineHandler()); + } + public char getKey() { return key; } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleStateManager.java b/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleStateManager.java index a344770dc0d83..0caa94cc7417b 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleStateManager.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleStateManager.java @@ -100,6 +100,7 @@ public static void init(QuarkusConsole console, DevModeType devModeType) { } void installBuiltins(DevModeType devModeType) { + ConsoleContext context = createContext("System"); List commands = new ArrayList<>(); if (devModeType != DevModeType.TEST_ONLY) { commands.add(new ConsoleCommand('s', "Force restart", null, () -> { @@ -121,6 +122,12 @@ public void accept(String args) { Logger.getLogger(ConsoleStateManager.class).errorf(e, "Failed to parse command line %s", args); return; } + // Reload command + context.reset(ConsoleCommand.duplicateCommandWithNewPromptString(context.getCommandByKey('e'), + "to edit command line args (currently '" + MessageFormat.GREEN + + String.join(" ", RuntimeUpdatesProcessor.INSTANCE.getCommandLineArgs()) + + MessageFormat.RESET + + "')")); RuntimeUpdatesProcessor.INSTANCE.doScan(true, true); } })); @@ -145,8 +152,6 @@ public void accept(String args) { })); } - ConsoleContext context = createContext("System"); - commands.add(new ConsoleCommand('j', "Toggle log levels", new ConsoleCommand.HelpState(() -> currentLevel == null ? BLUE : RED, () -> (currentLevel == null @@ -280,8 +285,9 @@ public ConsoleContext createContext(String name) { void redraw() { List sorted = commands.values().stream().map(s -> s.consoleCommand) - .filter(s -> s.getPromptString() != null).sorted(Comparator.comparingInt(ConsoleCommand::getPromptPriority)) - .collect(Collectors.toList()); + .filter(s -> s.getPromptString() != null) + .sorted(Comparator.comparingInt(ConsoleCommand::getPromptPriority)) + .toList(); if (sorted.isEmpty()) { QuarkusConsole.INSTANCE.setPromptMessage(null); oldPrompt = null; @@ -338,6 +344,12 @@ public void addCommandInternal(ConsoleCommand consoleCommand) { } } + public ConsoleCommand getCommandByKey(Character key) { + synchronized (commands) { + return commands.get(key).consoleCommand; + } + } + public void reset(ConsoleCommand... command) { synchronized (commands) { internal.clear();