in src/main/java/org/apache/sling/cli/impl/CommandProcessor.java [87:129]
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 = arguments(ctx.getProperty(EXEC_ARGS));
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 {
try {
ctx.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).adapt(Framework.class).stop();
} catch (BundleException e) {
logger.error("Failed shutting down framework, forcing exit", e);
System.exit(1);
}
}
System.exit(commandExitCode);
}