Search in sources :

Example 1 with CommandRegistry

use of org.aesh.command.registry.CommandRegistry in project infinispan by infinispan.

the class CLI method batch.

private CommandResult batch(String inputFile, Shell shell) {
    CommandRegistry commandRegistry = initializeCommands(Batch.class);
    AeshCommandRuntimeBuilder runtimeBuilder = AeshCommandRuntimeBuilder.builder();
    runtimeBuilder.commandActivatorProvider(new ContextAwareCommandActivatorProvider(context)).commandInvocationProvider(new ContextAwareCommandInvocationProvider(context)).commandNotFoundHandler(new CliCommandNotFoundHandler()).completerInvocationProvider(new ContextAwareCompleterInvocationProvider(context)).aeshContext(context).commandRegistry(commandRegistry);
    runtimeBuilder.shell(shell);
    CliRuntimeRunner cliRunner = new CliRuntimeRunner("batch", runtimeBuilder.build());
    int exitCode = cliRunner.args(new String[] { "run", inputFile }).execute();
    context.disconnect();
    return CommandResult.valueOf(exitCode);
}
Also used : CommandRegistry(org.aesh.command.registry.CommandRegistry) AeshCommandRuntimeBuilder(org.aesh.command.AeshCommandRuntimeBuilder) CliCommandNotFoundHandler(org.infinispan.cli.impl.CliCommandNotFoundHandler) ContextAwareCompleterInvocationProvider(org.infinispan.cli.completers.ContextAwareCompleterInvocationProvider) CliRuntimeRunner(org.infinispan.cli.impl.CliRuntimeRunner) ContextAwareCommandActivatorProvider(org.infinispan.cli.activators.ContextAwareCommandActivatorProvider) ContextAwareCommandInvocationProvider(org.infinispan.cli.impl.ContextAwareCommandInvocationProvider)

Example 2 with CommandRegistry

use of org.aesh.command.registry.CommandRegistry in project keycloak by keycloak.

the class AddUser method printHelp.

private static void printHelp(Command command) throws CommandNotFoundException, CommandRegistryException {
    CommandRegistry registry = AeshCommandRegistryBuilder.builder().command(command).create();
    CommandContainer commandContainer = registry.getCommand(command.getClass().getAnnotation(CommandDefinition.class).name(), null);
    String help = commandContainer.printHelp(null);
    System.out.println(help);
}
Also used : CommandRegistry(org.aesh.command.registry.CommandRegistry) CommandContainer(org.aesh.command.container.CommandContainer)

Example 3 with CommandRegistry

use of org.aesh.command.registry.CommandRegistry 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 4 with CommandRegistry

use of org.aesh.command.registry.CommandRegistry in project infinispan by infinispan.

the class CLI method interactive.

private CommandResult interactive(Shell shell) {
    // We now start an interactive CLI
    CommandRegistry commandRegistry = initializeCommands();
    context.setRegistry(commandRegistry);
    CliAliasManager aliasManager;
    try {
        aliasManager = new CliAliasManager(context.getConfigPath().resolve("aliases").toFile(), true, commandRegistry);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    SettingsBuilder settings = SettingsBuilder.builder();
    settings.enableAlias(true).aliasManager(aliasManager).historyFile(context.getConfigPath().resolve("history").toFile()).outputStream(System.out).outputStreamError(System.err).inputStream(System.in).commandActivatorProvider(new ContextAwareCommandActivatorProvider(context)).commandInvocationProvider(new ContextAwareCommandInvocationProvider(context)).commandNotFoundHandler(new CliCommandNotFoundHandler()).completerInvocationProvider(new ContextAwareCompleterInvocationProvider(context)).commandRegistry(commandRegistry).aeshContext(context).quitHandler(new ContextAwareQuitHandler(context));
    if (shell instanceof AeshDelegatingShell) {
        settings.connection(((AeshDelegatingShell) shell).getConnection());
    }
    ReadlineConsole console = new ReadlineConsole(settings.build());
    context.setConsole(console);
    try {
        console.start();
        return CommandResult.SUCCESS;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : SettingsBuilder(org.aesh.command.settings.SettingsBuilder) CommandRegistry(org.aesh.command.registry.CommandRegistry) CliAliasManager(org.infinispan.cli.impl.CliAliasManager) AeshDelegatingShell(org.infinispan.cli.impl.AeshDelegatingShell) ReadlineConsole(org.aesh.readline.ReadlineConsole) ContextAwareQuitHandler(org.infinispan.cli.impl.ContextAwareQuitHandler) IOException(java.io.IOException) CliCommandNotFoundHandler(org.infinispan.cli.impl.CliCommandNotFoundHandler) ContextAwareCompleterInvocationProvider(org.infinispan.cli.completers.ContextAwareCompleterInvocationProvider) ContextAwareCommandActivatorProvider(org.infinispan.cli.activators.ContextAwareCommandActivatorProvider) ContextAwareCommandInvocationProvider(org.infinispan.cli.impl.ContextAwareCommandInvocationProvider)

Aggregations

CommandRegistry (org.aesh.command.registry.CommandRegistry)4 IOException (java.io.IOException)2 ReadlineConsole (org.aesh.readline.ReadlineConsole)2 ContextAwareCommandActivatorProvider (org.infinispan.cli.activators.ContextAwareCommandActivatorProvider)2 ContextAwareCompleterInvocationProvider (org.infinispan.cli.completers.ContextAwareCompleterInvocationProvider)2 CliCommandNotFoundHandler (org.infinispan.cli.impl.CliCommandNotFoundHandler)2 ContextAwareCommandInvocationProvider (org.infinispan.cli.impl.ContextAwareCommandInvocationProvider)2 AeshCommandRuntimeBuilder (org.aesh.command.AeshCommandRuntimeBuilder)1 CommandContainer (org.aesh.command.container.CommandContainer)1 CommandInvocation (org.aesh.command.invocation.CommandInvocation)1 Settings (org.aesh.command.settings.Settings)1 SettingsBuilder (org.aesh.command.settings.SettingsBuilder)1 AliasManager (org.aesh.readline.alias.AliasManager)1 AeshDelegatingShell (org.infinispan.cli.impl.AeshDelegatingShell)1 CliAliasManager (org.infinispan.cli.impl.CliAliasManager)1 CliRuntimeRunner (org.infinispan.cli.impl.CliRuntimeRunner)1 ContextAwareQuitHandler (org.infinispan.cli.impl.ContextAwareQuitHandler)1