From 1d813f2fd1c6d3b578e345215d21dbdd2b480c5c Mon Sep 17 00:00:00 2001 From: Erin Schnabel Date: Wed, 8 Sep 2021 17:28:59 -0400 Subject: [PATCH] CLI: change rendering of nested subcommands in help --- .../io/quarkus/cli/ProjectExtensions.java | 2 +- .../main/java/io/quarkus/cli/QuarkusCli.java | 19 ++++++++++++------- .../main/java/io/quarkus/cli/Registry.java | 2 +- .../io/quarkus/cli/RegistryAddCommand.java | 4 ++-- .../io/quarkus/cli/RegistryListCommand.java | 2 +- .../io/quarkus/cli/RegistryRemoveCommand.java | 4 ++-- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/devtools/cli/src/main/java/io/quarkus/cli/ProjectExtensions.java b/devtools/cli/src/main/java/io/quarkus/cli/ProjectExtensions.java index 39d60cba9577e..a166379e57d61 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/ProjectExtensions.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/ProjectExtensions.java @@ -10,7 +10,7 @@ import picocli.CommandLine.Unmatched; @CommandLine.Command(name = "extension", aliases = { - "ext" }, sortOptions = false, mixinStandardHelpOptions = false, header = "List, add, and remove extensions of an existing project.", subcommands = { + "ext" }, sortOptions = false, mixinStandardHelpOptions = false, header = "Configure extensions of an existing project.", subcommands = { ProjectExtensionsList.class, ProjectExtensionsCategories.class, ProjectExtensionsAdd.class, ProjectExtensionsRemove.class }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "Options:%n") diff --git a/devtools/cli/src/main/java/io/quarkus/cli/QuarkusCli.java b/devtools/cli/src/main/java/io/quarkus/cli/QuarkusCli.java index 3510185f29084..346915aacb402 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/QuarkusCli.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/QuarkusCli.java @@ -3,7 +3,6 @@ import static picocli.CommandLine.Model.UsageMessageSpec.SECTION_KEY_COMMAND_LIST; import java.util.Collection; -import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.Callable; @@ -94,22 +93,28 @@ public String render(Help help) { if (spec.subcommands().isEmpty()) { return ""; } - Map tableElements = new LinkedHashMap<>(); - addHierarchy(spec.subcommands().values(), tableElements, ""); - return help.createTextTable(tableElements).toString(); + + Help.Column commands = new Help.Column(24, 2, CommandLine.Help.Column.Overflow.SPAN); + Help.Column descriptions = new Help.Column(spec.usageMessage().width() - 24, 2, + CommandLine.Help.Column.Overflow.WRAP); + Help.TextTable textTable = Help.TextTable.forColumns(help.colorScheme(), commands, descriptions); + textTable.setAdjustLineBreaksForWideCJKCharacters(spec.usageMessage().adjustLineBreaksForWideCJKCharacters()); + + addHierarchy(spec.subcommands().values(), textTable, ""); + return textTable.toString(); } - private void addHierarchy(Collection collection, Map tableElements, + private void addHierarchy(Collection collection, Help.TextTable textTable, String indent) { collection.stream().distinct().forEach(subcommand -> { // create comma-separated list of command name and aliases String names = String.join(", ", subcommand.getCommandSpec().names()); String description = description(subcommand.getCommandSpec().usageMessage()); - tableElements.put(indent + names, description); + textTable.addRowValues(indent + names, description); Map subcommands = subcommand.getSubcommands(); if (!subcommands.isEmpty()) { - addHierarchy(subcommands.values(), tableElements, indent + " "); + addHierarchy(subcommands.values(), textTable, indent + " "); } }); } diff --git a/devtools/cli/src/main/java/io/quarkus/cli/Registry.java b/devtools/cli/src/main/java/io/quarkus/cli/Registry.java index f88d0e04c8da3..d46ec57f0a26b 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/Registry.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/Registry.java @@ -7,7 +7,7 @@ import picocli.CommandLine.ParseResult; import picocli.CommandLine.Unmatched; -@CommandLine.Command(name = "registry", sortOptions = false, mixinStandardHelpOptions = false, header = "Manage extension registries.", subcommands = { +@CommandLine.Command(name = "registry", sortOptions = false, mixinStandardHelpOptions = false, header = "Configure Quarkus registry client", subcommands = { RegistryAddCommand.class, RegistryListCommand.class, RegistryRemoveCommand.class }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "%nOptions:%n") diff --git a/devtools/cli/src/main/java/io/quarkus/cli/RegistryAddCommand.java b/devtools/cli/src/main/java/io/quarkus/cli/RegistryAddCommand.java index f1e6b6c31a31f..73194c506c8e3 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/RegistryAddCommand.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/RegistryAddCommand.java @@ -16,8 +16,8 @@ import io.quarkus.registry.config.json.RegistriesConfigMapperHelper; import picocli.CommandLine; -@CommandLine.Command(name = "add", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Add a Quarkus extension registry to the registry client configuration", description = "%n" - + "This command will add a Quarkus extension registry to the registry client configuration unless it's already present", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n") +@CommandLine.Command(name = "add", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Add a Quarkus extension registry", description = "%n" + + "This command will add a Quarkus extension registry to the registry client configuration unless it's already present.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n") public class RegistryAddCommand extends BaseRegistryCommand { @CommandLine.Mixin diff --git a/devtools/cli/src/main/java/io/quarkus/cli/RegistryListCommand.java b/devtools/cli/src/main/java/io/quarkus/cli/RegistryListCommand.java index 96872de2fba79..79879122707bb 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/RegistryListCommand.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/RegistryListCommand.java @@ -14,7 +14,7 @@ import picocli.CommandLine; @CommandLine.Command(name = "list", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "List enabled Quarkus registries", description = "%n" - + "This command will list currently enabled Quarkus extension registries", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n") + + "This command will list currently enabled Quarkus extension registries.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n") public class RegistryListCommand extends BaseRegistryCommand { @CommandLine.Mixin diff --git a/devtools/cli/src/main/java/io/quarkus/cli/RegistryRemoveCommand.java b/devtools/cli/src/main/java/io/quarkus/cli/RegistryRemoveCommand.java index a3a3a649f19eb..6d159ce28e51f 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/RegistryRemoveCommand.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/RegistryRemoveCommand.java @@ -15,8 +15,8 @@ import io.quarkus.registry.config.json.RegistriesConfigMapperHelper; import picocli.CommandLine; -@CommandLine.Command(name = "remove", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Remove a Quarkus extension registry from the registry client configuration", description = "%n" - + "This command will remove a Quarkus extension registry from the registry client configuration", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n") +@CommandLine.Command(name = "remove", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Remove a Quarkus extension registry", description = "%n" + + "This command will remove a Quarkus extension registry from the registry client configuration.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n") public class RegistryRemoveCommand extends BaseRegistryCommand { @CommandLine.Mixin