Search in sources :

Example 1 with CommandInvocation

use of org.aesh.command.invocation.CommandInvocation in project quarkus by quarkusio.

the class AeshConsole method runAeshCli.

public void runAeshCli() {
    if (ConsoleCliManager.commands.isEmpty()) {
        System.out.println("No commands registered, please wait for Quarkus to start before using the console");
        return;
    }
    try {
        pauseOutput = true;
        delegateConnection = new DelegateConnection(connection);
        connection.write(ALTERNATE_SCREEN_BUFFER);
        if (firstConsoleRun) {
            connection.write("You are now in Quarkus Terminal. Your app is still running. Use `help` or tab completion to explore, `quit` or `q` to return to your application.\n");
            firstConsoleRun = false;
        }
        AeshCommandRegistryBuilder<CommandInvocation> commandBuilder = AeshCommandRegistryBuilder.builder();
        ConsoleCliManager.commands.forEach(commandBuilder::command);
        CommandRegistry registry = commandBuilder.create();
        Settings settings = SettingsBuilder.builder().enableExport(false).enableAlias(true).aliasManager(new AliasManager(Paths.get(System.getProperty("user.home")).resolve(ALIAS_FILE).toFile(), true)).connection(delegateConnection).commandRegistry(registry).build();
        aeshConsole = new ReadlineConsole(settings);
        aeshConsole.setPrompt("quarkus$ ");
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    aeshConsole.start();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }, "Quarkus integrated CLI thread");
        t.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CommandRegistry(org.aesh.command.registry.CommandRegistry) IOException(java.io.IOException) IOException(java.io.IOException) CommandInvocation(org.aesh.command.invocation.CommandInvocation) AliasManager(org.aesh.readline.alias.AliasManager) ReadlineConsole(org.aesh.readline.ReadlineConsole) Settings(org.aesh.command.settings.Settings)

Example 2 with CommandInvocation

use of org.aesh.command.invocation.CommandInvocation 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)

Example 3 with CommandInvocation

use of org.aesh.command.invocation.CommandInvocation in project infinispan by infinispan.

the class GraalReflectionCommand method execute.

@Override
public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
    if (help) {
        commandInvocation.getHelpInfo("graalreflection");
    } else {
        Class<Command<CommandInvocation>> clazz = loadCommand(command);
        if (clazz != null) {
            CommandContainerBuilder<CommandInvocation> builder = new AeshCommandContainerBuilder<>();
            try {
                CommandContainer<CommandInvocation> container = builder.create(clazz);
                GraalReflectionFileGenerator graalFileGenerator = new GraalReflectionFileGenerator();
                try (BufferedWriter w = Files.newBufferedWriter(Paths.get(container.getParser().getProcessedCommand().name().toLowerCase() + "_reflection.json"), StandardOpenOption.CREATE)) {
                    graalFileGenerator.generateReflection(container.getParser(), w);
                }
                container.getParser().getProcessedCommand();
            } catch (CommandLineParserException | IOException e) {
                e.printStackTrace();
            }
        } else
            commandInvocation.println("Could not load command: " + command);
    }
    return CommandResult.SUCCESS;
}
Also used : Command(org.aesh.command.Command) AeshCommandContainerBuilder(org.aesh.command.impl.container.AeshCommandContainerBuilder) IOException(java.io.IOException) CommandLineParserException(org.aesh.command.parser.CommandLineParserException) CommandInvocation(org.aesh.command.invocation.CommandInvocation) BufferedWriter(java.io.BufferedWriter)

Aggregations

IOException (java.io.IOException)3 CommandInvocation (org.aesh.command.invocation.CommandInvocation)3 Command (org.aesh.command.Command)2 BufferedWriter (java.io.BufferedWriter)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 CommandDefinition (org.aesh.command.CommandDefinition)1 CommandException (org.aesh.command.CommandException)1 CommandResult (org.aesh.command.CommandResult)1 AeshCommandContainerBuilder (org.aesh.command.impl.container.AeshCommandContainerBuilder)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 CommandLineParserException (org.aesh.command.parser.CommandLineParserException)1 CommandRegistry (org.aesh.command.registry.CommandRegistry)1 ManProvider (org.aesh.command.settings.ManProvider)1