Search in sources :

Example 1 with CommandDomain

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();
}
Also used : CommandDomain(org.jboss.galleon.cli.cmd.CommandDomain) Set(java.util.Set) TreeSet(java.util.TreeSet) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 2 with CommandDomain

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());
    }
}
Also used : ProcessedOption(org.aesh.command.impl.internal.ProcessedOption) CommandDomain(org.jboss.galleon.cli.cmd.CommandDomain)

Aggregations

CommandDomain (org.jboss.galleon.cli.cmd.CommandDomain)2 Map (java.util.Map)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 ProcessedOption (org.aesh.command.impl.internal.ProcessedOption)1