void runCommand()

in src/main/java/org/apache/sling/cli/impl/CommandProcessor.java [100:137]


    void runCommand() {
        System.setProperty("picocli.usage.width", "140");
        CommandLine commandLine = new CommandLine(this);
        commandLine.addSubcommand(CommandLine.HelpCommand.class);
        for (Map.Entry<String, TreeSet<CommandWithProps>> entry : commands.entrySet()) {
            String group = entry.getKey();
            Class<?> groupClass = CLI_GROUPS.get(group);
            if (groupClass != null) {
                CommandLine secondary = new CommandLine(groupClass);
                for (CommandWithProps command : entry.getValue()) {
                    secondary.addSubcommand(command.name, command.cmd);
                }
                secondary.addSubcommand(CommandLine.HelpCommand.class);
                commandLine.addSubcommand(group, secondary);
            } else {
                for (CommandWithProps command : entry.getValue()) {
                    commandLine.addSubcommand(command.group, command.cmd);
                }
            }
        }
        int commandExitCode;
        try {
            String[] arguments = getArgLine().split("\\n");
            commandExitCode = commandLine.execute(arguments);
        } catch (CommandLine.ParameterException e) {
            commandLine.getErr().println(e.getMessage());
            if (!CommandLine.UnmatchedArgumentException.printSuggestions(e, commandLine.getErr())) {
                e.getCommandLine().usage(commandLine.getErr());
            }
            commandExitCode = commandLine.getCommandSpec().exitCodeOnInvalidInput();
        } catch (Exception e) {
            logger.warn("Failed running command.", e);
            commandExitCode = 1;
        } finally {
            stopFramework();
        }
        terminateExecution(commandExitCode);
    }