Skip to content

Commit

Permalink
Fix quarkus dev broken for command mode arguments
Browse files Browse the repository at this point in the history
(cherry picked from commit 3c20237)
  • Loading branch information
MaciejDromin authored and gsmet committed Jan 23, 2024
1 parent 02ea779 commit ccc23f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static void init(QuarkusConsole console, DevModeType devModeType) {
}

void installBuiltins(DevModeType devModeType) {
ConsoleContext context = createContext("System");
List<ConsoleCommand> commands = new ArrayList<>();
if (devModeType != DevModeType.TEST_ONLY) {
commands.add(new ConsoleCommand('s', "Force restart", null, () -> {
Expand All @@ -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);
}
}));
Expand All @@ -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
Expand Down Expand Up @@ -280,8 +285,9 @@ public ConsoleContext createContext(String name) {
void redraw() {

List<ConsoleCommand> 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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit ccc23f4

Please sign in to comment.