use of org.jboss.as.cli.impl.aesh.cmd.operation.LegacyCommandContainer.LegacyCommand in project wildfly-core by wildfly.
the class HelpCommand method execute.
@Override
public CommandResult execute(CLICommandInvocation commandInvocation) throws CommandException, InterruptedException {
CommandContext ctx = commandInvocation.getCommandContext();
if (command == null || command.isEmpty()) {
if (commands) {
return listAvailable(commandInvocation);
} else {
ctx.printLine(commandInvocation.getHelpInfo("help"));
}
return CommandResult.SUCCESS;
}
if (commands) {
throw new CommandException("commands option not usable with an argument");
}
if (command.size() > 2) {
throw new CommandException("Command has more than one action");
}
String mainCommand = command.get(0);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < command.size(); i++) {
builder.append(command.get(i));
if (i < command.size() - 1) {
builder.append(" ");
}
}
// An operation?
if (OperationCommandContainer.isOperation(mainCommand)) {
try {
ctx.printLine(getOperationHelp(builder.toString(), commandInvocation.getCommandContext()));
} catch (Exception ex) {
ctx.printLine("Error getting operation help: " + ex.getLocalizedMessage());
}
return CommandResult.SUCCESS;
}
try {
CommandLineParser parser = aeshRegistry.findCommand(mainCommand, builder.toString());
// Special case for generic command that generates the help content on the fly.
if (parser.getProcessedCommand().getCommand() instanceof LegacyCommand) {
CommandHandler handler = ((LegacyCommand) parser.getProcessedCommand().getCommand()).getCommandHandler();
if (handler instanceof GenericTypeOperationHandler) {
try {
((GenericTypeOperationHandler) handler).printDescription(commandInvocation.getCommandContext());
} catch (CommandLineException ex1) {
throw new CommandException(ex1);
}
// We can only rely on handler, handler hides the actual file path
// to its help. eg: remove-batch-line is actually batch-remove-line.txt
} else if (handler instanceof CommandHandlerWithHelp) {
try {
((CommandHandlerWithHelp) handler).displayHelp(commandInvocation.getCommandContext());
} catch (CommandLineException ex1) {
throw new CommandException(ex1);
}
}
} else {
ctx.printLine(parser.printHelp());
}
} catch (CommandNotFoundException ex) {
throw new CommandException("Command " + builder.toString() + " does not exist.");
}
return CommandResult.SUCCESS;
}
Aggregations