Search in sources :

Example 1 with ManProvider

use of org.aesh.command.settings.ManProvider 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;
}
Also used : CommandDefinition(org.aesh.command.CommandDefinition) Parser(org.aesh.readline.util.Parser) ManProvider(org.aesh.command.settings.ManProvider) MetaInfServices(org.kohsuke.MetaInfServices) TerminalPage(org.aesh.command.man.TerminalPage) Command(org.aesh.command.Command) FileParser(org.aesh.command.man.FileParser) ArrayList(java.util.ArrayList) ManFileParser(org.aesh.command.man.parser.ManFileParser) CommandResult(org.aesh.command.CommandResult) ANSI(org.aesh.terminal.utils.ANSI) Shell(org.aesh.command.shell.Shell) Config(org.aesh.terminal.utils.Config) ContextAwareCommandInvocation(org.infinispan.cli.impl.ContextAwareCommandInvocation) CliManProvider(org.infinispan.cli.impl.CliManProvider) IOException(java.io.IOException) CommandInvocation(org.aesh.command.invocation.CommandInvocation) Collectors(java.util.stream.Collectors) CommandException(org.aesh.command.CommandException) Arguments(org.aesh.command.option.Arguments) List(java.util.List) TerminalString(org.aesh.readline.terminal.formatting.TerminalString) AeshFileDisplayer(org.aesh.command.man.AeshFileDisplayer) HelpCompleter(org.infinispan.cli.completers.HelpCompleter) InputStream(java.io.InputStream) Shell(org.aesh.command.shell.Shell) InputStream(java.io.InputStream) TerminalString(org.aesh.readline.terminal.formatting.TerminalString) IOException(java.io.IOException) CommandException(org.aesh.command.CommandException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Command (org.aesh.command.Command)1 CommandDefinition (org.aesh.command.CommandDefinition)1 CommandException (org.aesh.command.CommandException)1 CommandResult (org.aesh.command.CommandResult)1 CommandInvocation (org.aesh.command.invocation.CommandInvocation)1 AeshFileDisplayer (org.aesh.command.man.AeshFileDisplayer)1 FileParser (org.aesh.command.man.FileParser)1 TerminalPage (org.aesh.command.man.TerminalPage)1 ManFileParser (org.aesh.command.man.parser.ManFileParser)1 Arguments (org.aesh.command.option.Arguments)1 ManProvider (org.aesh.command.settings.ManProvider)1 Shell (org.aesh.command.shell.Shell)1 TerminalString (org.aesh.readline.terminal.formatting.TerminalString)1 Parser (org.aesh.readline.util.Parser)1 ANSI (org.aesh.terminal.utils.ANSI)1