From 7eaad48b9a541d926a24afb6a071d1f4ea18e249 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Sat, 25 Mar 2023 19:11:48 +0100 Subject: [PATCH] Improve the dev mode console output - More consistency for the options - Improve wording of some options - Display configuration properties on separate lines --- .../deployment/console/ConsoleProcessor.java | 8 +-- .../console/ConsoleStateManager.java | 8 +-- .../DevServiceDescriptionBuildItem.java | 4 +- .../deployment/DevServicesLogsCommand.java | 2 +- .../deployment/DevServicesProcessor.java | 63 ++++++++++++++----- 5 files changed, 58 insertions(+), 27 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleProcessor.java index a1811e8e6f74a..b7fb567f528c7 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleProcessor.java @@ -105,7 +105,7 @@ public void accept(Throwable throwable, StackTraceElement stackTraceElement) { } context.reset( - new ConsoleCommand('x', "Opens last exception in IDE", new ConsoleCommand.HelpState(new Supplier() { + new ConsoleCommand('x', "Open last exception in IDE", new ConsoleCommand.HelpState(new Supplier() { @Override public String get() { return MessageFormat.RED; @@ -115,7 +115,7 @@ public String get() { public String get() { StackTraceElement throwable = lastUserCode.get(); if (throwable == null) { - return "None"; + return "none"; } return throwable.getFileName() + ":" + throwable.getLineNumber(); } @@ -179,7 +179,7 @@ ConsoleCommandBuildItem quitCommand() { return new ConsoleCommandBuildItem(new QuitCommand()); } - @CommandDefinition(name = "quit", description = "Quits the console", aliases = { "q" }) + @CommandDefinition(name = "quit", description = "Quit the console", aliases = { "q" }) public static class QuitCommand implements Command { @Override @@ -194,7 +194,7 @@ ConsoleCommandBuildItem helpCommand() { return new ConsoleCommandBuildItem(new HelpCommand()); } - @CommandDefinition(name = "help", description = "Displays the command list", aliases = { "h" }) + @CommandDefinition(name = "help", description = "Display the command list", aliases = { "h" }) public static class HelpCommand implements Command { @Override 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 e6671d5ae3516..a21da1453d722 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 @@ -128,12 +128,12 @@ void installBuiltins(DevModeType devModeType) { ConsoleStateManager.this::toggleLogLevel)); commands.add(new ConsoleCommand((char) 12, null, null, 10002, null, this::clearScreen)); commands.add(new ConsoleCommand((char) 13, null, null, 10001, null, this::printBlankLine)); - commands.add(new ConsoleCommand('h', "Shows this help", "for more options", 10000, null, this::printHelp)); + commands.add(new ConsoleCommand('h', "Show this help", "for more options", 10000, null, this::printHelp)); if (QuarkusConsole.INSTANCE instanceof AeshConsole) { - commands.add(new ConsoleCommand(':', "Enters terminal mode", "for the terminal", 9000, null, () -> { + commands.add(new ConsoleCommand(':', "Enter terminal mode", "for the terminal", 9000, null, () -> { })); } - commands.add(new ConsoleCommand('q', "Quits the application", null, this::exitQuarkus)); + commands.add(new ConsoleCommand('q', "Quit the application", null, this::exitQuarkus)); context.reset(commands.toArray(new ConsoleCommand[0])); } @@ -198,7 +198,7 @@ private void printBlankLine() { } private void printHelp() { - System.out.println("\nThe following commands are currently available:"); + System.out.println("\nThe following commands are available:"); Set contexts = new HashSet<>(); for (Holder i : commands.values()) { contexts.add(i.context); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/devservices/DevServiceDescriptionBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/devservices/DevServiceDescriptionBuildItem.java index 9d9374a342c4c..c5b7651297c0e 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/devservices/DevServiceDescriptionBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/devservices/DevServiceDescriptionBuildItem.java @@ -1,6 +1,8 @@ package io.quarkus.deployment.dev.devservices; import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; import java.util.stream.Collectors; import io.quarkus.builder.item.MultiBuildItem; @@ -16,7 +18,7 @@ public DevServiceDescriptionBuildItem() { public DevServiceDescriptionBuildItem(String name, ContainerInfo containerInfo, Map configs) { this.name = name; this.containerInfo = containerInfo; - this.configs = configs; + this.configs = configs instanceof SortedMap ? configs : new TreeMap<>(configs); } public boolean hasContainerInfo() { diff --git a/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesLogsCommand.java b/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesLogsCommand.java index de75cd0cdbca2..d8f8df7f152d4 100644 --- a/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesLogsCommand.java +++ b/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesLogsCommand.java @@ -60,7 +60,7 @@ public CommandResult execute(CommandInvocation commandInvocation) { } return CommandResult.SUCCESS; } else { - commandInvocation.println("Could not find dev service with name " + this.devService); + commandInvocation.println("Could not find Dev Service with name " + this.devService); return CommandResult.FAILURE; } } diff --git a/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesProcessor.java b/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesProcessor.java index a7a5a035961c7..bb299dc590516 100644 --- a/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesProcessor.java +++ b/extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/DevServicesProcessor.java @@ -8,7 +8,19 @@ import static io.quarkus.deployment.dev.testing.MessageFormat.RESET; import static io.quarkus.deployment.dev.testing.MessageFormat.UNDERLINE; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.TreeMap; import java.util.function.Function; import java.util.stream.Collectors; @@ -31,10 +43,12 @@ import io.quarkus.deployment.dev.devservices.ContainerInfo; import io.quarkus.deployment.dev.devservices.DevServiceDescriptionBuildItem; import io.quarkus.dev.spi.DevModeType; +import io.quarkus.runtime.util.ContainerRuntimeUtil; +import io.quarkus.runtime.util.ContainerRuntimeUtil.ContainerRuntime; public class DevServicesProcessor { - private static final String EXEC_FORMAT = "docker exec -it %s /bin/bash"; + private static final String EXEC_FORMAT = "%s exec -it %s /bin/bash"; static volatile ConsoleStateManager.ConsoleContext context; static volatile boolean logForwardEnabled = false; @@ -70,7 +84,7 @@ public List config( context = ConsoleStateManager.INSTANCE.createContext("Dev Services"); } context.reset( - new ConsoleCommand('c', "Show dev services containers", null, () -> { + new ConsoleCommand('c', "Show Dev Services containers", null, () -> { List descriptions = buildServiceDescriptions( dockerStatusBuildItem, devServicesResults, devServicesLauncherConfig); StringBuilder builder = new StringBuilder(); @@ -83,7 +97,7 @@ public List config( } System.out.println(builder); }), - new ConsoleCommand('g', "Follow dev services logs to the console", + new ConsoleCommand('g', "Follow Dev Services logs in the console", new ConsoleCommand.HelpState(() -> logForwardEnabled ? GREEN : RED, () -> logForwardEnabled ? "enabled" : "disabled"), this::toggleLogForwarders)); @@ -111,12 +125,12 @@ private List buildServiceDescriptions( descriptions.sort(Comparator.comparing(DevServiceDescriptionBuildItem::getName)); // Add description from other dev service configs as last if (devServicesLauncherConfig.isPresent()) { - Map config = new HashMap<>(devServicesLauncherConfig.get().getConfig()); + Map config = new TreeMap<>(devServicesLauncherConfig.get().getConfig()); for (String key : configKeysFromDevServices) { config.remove(key); } if (!config.isEmpty()) { - descriptions.add(new DevServiceDescriptionBuildItem("Other Dev Services", null, config)); + descriptions.add(new DevServiceDescriptionBuildItem("Additional Dev Services config", null, config)); } } return descriptions; @@ -191,12 +205,10 @@ private synchronized void toggleLogForwarders() { } public static void printDevService(StringBuilder builder, DevServiceDescriptionBuildItem devService, boolean withStatus) { + builder.append(BOLD).append(devService.getName()).append(NO_BOLD); + builder.append("\n"); + if (devService.hasContainerInfo()) { - builder.append(BOLD).append(devService.getName()).append(NO_BOLD); - if (withStatus) { - builder.append(" - ").append(devService.getContainerInfo().getStatus()); - } - builder.append("\n"); builder.append(String.format(" %-18s", "Container: ")) .append(devService.getContainerInfo().getId(), 0, 12) .append(devService.getContainerInfo().formatNames()) @@ -208,13 +220,30 @@ public static void printDevService(StringBuilder builder, DevServiceDescriptionB .append(" - ") .append(devService.getContainerInfo().formatPorts()) .append("\n"); - builder.append(String.format(" %-18s", "Exec command: ")) - .append(String.format(EXEC_FORMAT, devService.getContainerInfo().getShortId())) - .append("\n"); + + ContainerRuntime containerRuntime = ContainerRuntimeUtil.detectContainerRuntime(false); + if (containerRuntime != null) { + builder.append(String.format(" %-18s", "Exec command: ")) + .append(String.format(EXEC_FORMAT, + containerRuntime.getExecutableName(), + devService.getContainerInfo().getShortId())) + .append("\n"); + } + } + + if (!devService.getConfigs().isEmpty()) { + builder.append(String.format(" %-18s", "Injected config: ")); + boolean indent = false; + for (Entry devServiceConfigEntry : devService.getConfigs().entrySet()) { + if (indent) { + builder.append(String.format(" %-18s", " ")); + } + builder.append( + String.format("- %s=%s\n", + devServiceConfigEntry.getKey(), devServiceConfigEntry.getValue())); + indent = true; + } } - builder.append(String.format(" %-18s", "Injected Config: ")) - .append(devService.formatConfigs()) - .append("\n"); } }