use of org.jboss.galleon.cli.cmd.CommandDomain in project galleon by wildfly.
the class HelpSupport method buildHelp.
private static String buildHelp(CommandRegistry<? extends CommandInvocation> registry, Set<String> commands, boolean footer) throws CommandNotFoundException {
TreeMap<CommandDomain, Set<String>> groupedCommands = new TreeMap<>();
for (String command : commands) {
CommandDomain group = CommandDomain.getDomain(registry.getCommand(command, null).getParser().getCommand());
String commandTree = getCommandTree(registry, command);
if (group == null) {
group = CommandDomain.OTHERS;
}
Set<String> currentDescriptions = groupedCommands.get(group);
if (currentDescriptions == null) {
currentDescriptions = new TreeSet<>();
groupedCommands.put(group, currentDescriptions);
}
currentDescriptions.add(commandTree);
}
StringBuilder sb = new StringBuilder();
for (Map.Entry<CommandDomain, Set<String>> groupedCommand : groupedCommands.entrySet()) {
sb.append(Config.getLineSeparator());
sb.append("== ").append(groupedCommand.getKey().getDescription()).append(" ==");
sb.append(Config.getLineSeparator());
for (String description : groupedCommand.getValue()) {
sb.append(description);
sb.append(Config.getLineSeparator());
}
}
if (footer) {
sb.append(getHelpFooter());
}
return sb.toString();
}
use of org.jboss.galleon.cli.cmd.CommandDomain in project galleon by wildfly.
the class HelpSupportTestCase method checkCommand.
private void checkCommand(ProcessedCommand<? extends Command<? extends CommandInvocation>, ? extends CommandInvocation> processedCommand, boolean child) {
CommandDomain domain = CommandDomain.getDomain(processedCommand.getCommand());
assertTrue(processedCommand.name(), processedCommand.description() != null && !processedCommand.description().isEmpty());
if (child) {
assertNull(processedCommand.name(), domain);
} else {
assertNotNull(processedCommand.name(), domain);
}
ProcessedOption arg = processedCommand.getArgument();
if (arg != null) {
assertTrue("Argument for " + processedCommand.name(), arg.description() != null && !arg.description().isEmpty());
}
ProcessedOption args = processedCommand.getArguments();
if (args != null) {
assertTrue("Arguments for " + processedCommand.name(), args.description() != null && !args.description().isEmpty());
}
for (ProcessedOption opt : processedCommand.getOptions()) {
assertTrue(opt.name() + " for " + processedCommand.name(), opt.description() != null && !opt.description().isEmpty());
}
}
Aggregations