Skip to content

Commit

Permalink
Merge pull request #20011 from ebullient/cli-help
Browse files Browse the repository at this point in the history
CLI: change rendering of nested subcommands in help
  • Loading branch information
aloubyansky committed Sep 9, 2021
2 parents e30c00a + 1d813f2 commit 5ddaf8d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 12 additions & 7 deletions devtools/cli/src/main/java/io/quarkus/cli/QuarkusCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -94,22 +93,28 @@ public String render(Help help) {
if (spec.subcommands().isEmpty()) {
return "";
}
Map<String, String> 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<CommandLine> collection, Map<String, String> tableElements,
private void addHierarchy(Collection<CommandLine> 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<String, CommandLine> subcommands = subcommand.getSubcommands();
if (!subcommands.isEmpty()) {
addHierarchy(subcommands.values(), tableElements, indent + " ");
addHierarchy(subcommands.values(), textTable, indent + " ");
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion devtools/cli/src/main/java/io/quarkus/cli/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ddaf8d

Please sign in to comment.