use of org.aesh.command.shell.Shell in project infinispan by infinispan.
the class Help method execute.
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
Shell shell = commandInvocation.getShell();
if (manPages == null || manPages.size() == 0) {
shell.writeln("Call `help <command>` where command is one of:");
List<TerminalString> commandNames = ((ContextAwareCommandInvocation) commandInvocation).getContext().getRegistry().getAllCommandNames().stream().map(n -> new TerminalString(n)).collect(Collectors.toList());
// then we print out the completions
shell.write(Parser.formatDisplayListTerminalString(commandNames, shell.size().getHeight(), shell.size().getWidth()));
// then on the next line we write the line again
shell.writeln("");
return CommandResult.SUCCESS;
}
if (manPages.size() <= 0) {
shell.write("No manual entry for " + manPages.get(0) + Config.getLineSeparator());
return CommandResult.SUCCESS;
}
if (manProvider == null) {
shell.write("No manual provider defined");
return CommandResult.SUCCESS;
}
InputStream inputStream = manProvider.getManualDocument(manPages.get(0));
if (inputStream != null) {
setCommandInvocation(commandInvocation);
try {
fileParser.setInput(inputStream);
afterAttach();
} catch (IOException ex) {
throw new CommandException(ex);
}
}
return CommandResult.SUCCESS;
}
use of org.aesh.command.shell.Shell in project infinispan by infinispan.
the class RestCliCommand method exec.
@Override
protected final CommandResult exec(ContextAwareCommandInvocation invocation) throws CommandException {
Shell shell = invocation.getShell();
Context context = invocation.getContext();
try {
String response = context.getConnection().execute((c, r) -> {
try {
return exec(invocation, c, r);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, getResponseMode());
if (response != null && !response.isEmpty()) {
shell.writeln(response);
}
invocation.getContext().refreshPrompt();
return CommandResult.SUCCESS;
} catch (Exception e) {
TerminalString error = new TerminalString(Util.getRootCause(e).getLocalizedMessage(), new TerminalColor(Color.RED, Color.DEFAULT, Color.Intensity.BRIGHT));
shell.writeln(error.toString());
invocation.getContext().refreshPrompt();
return CommandResult.FAILURE;
}
}
Aggregations