Search in sources :

Example 1 with ShellServiceOptions

use of io.vertx.ext.shell.ShellServiceOptions in project vertx-examples by vert-x3.

the class EchoKeyboardCommand method start.

@Override
public void start() throws Exception {
    Command starwars = CommandBuilder.command("echokeyboard").processHandler(process -> {
        // Echo
        process.stdinHandler(keys -> {
            process.write(keys.replace('\r', '\n'));
        });
        // Terminate when user hits Ctrl-C
        process.interruptHandler(v -> {
            process.end();
        });
    }).build(vertx);
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    CommandRegistry.getShared(vertx).registerCommand(starwars);
    service.start(ar -> {
        if (!ar.succeeded()) {
            ar.cause().printStackTrace();
        }
    });
}
Also used : TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) List(java.util.List) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) CommandRegistry(io.vertx.ext.shell.command.CommandRegistry) AbstractVerticle(io.vertx.core.AbstractVerticle) ShellService(io.vertx.ext.shell.ShellService) CommandBuilder(io.vertx.ext.shell.command.CommandBuilder) Runner(io.vertx.example.util.Runner) ArrayList(java.util.ArrayList) Formatter(java.util.Formatter) ShellService(io.vertx.ext.shell.ShellService) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions)

Example 2 with ShellServiceOptions

use of io.vertx.ext.shell.ShellServiceOptions in project vertx-examples by vert-x3.

the class RunShell method start.

@Override
public void start(Promise<Void> startPromise) throws Exception {
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setSSHOptions(new SSHTermOptions().setHost("localhost").setPort(3000).setKeyPairOptions(new JksOptions().setPath("keystore.jks").setPassword("wibble")).setAuthOptions(new ShiroAuthOptions().setConfig(new JsonObject().put("properties_path", "auth.properties")))));
    service.start(startPromise);
}
Also used : ShellService(io.vertx.ext.shell.ShellService) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) ShiroAuthOptions(io.vertx.ext.auth.shiro.ShiroAuthOptions) JksOptions(io.vertx.core.net.JksOptions) JsonObject(io.vertx.core.json.JsonObject) SSHTermOptions(io.vertx.ext.shell.term.SSHTermOptions)

Example 3 with ShellServiceOptions

use of io.vertx.ext.shell.ShellServiceOptions in project vertx-examples by vert-x3.

the class RunShell method start.

@Override
public void start() throws Exception {
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    service.start();
}
Also used : ShellService(io.vertx.ext.shell.ShellService) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions)

Example 4 with ShellServiceOptions

use of io.vertx.ext.shell.ShellServiceOptions in project vertx-examples by vert-x3.

the class TopCommand method start.

@Override
public void start() throws Exception {
    Command starwars = CommandBuilder.command("top").processHandler(process -> {
        long id = process.vertx().setPeriodic(500, id_ -> {
            StringBuilder buf = new StringBuilder();
            Formatter formatter = new Formatter(buf);
            List<Thread> threads = new ArrayList<>(Thread.getAllStackTraces().keySet());
            for (int i = 1; i <= process.height(); i++) {
                // Change cursor position and erase line with ANSI escape code magic
                buf.append("\033[").append(i).append(";1H\033[K");
                // 
                String format = "  %1$-5s %2$-20s %3$-50s %4$s";
                if (i == 1) {
                    formatter.format(format, "ID", "STATE", "NAME", "GROUP");
                } else {
                    int index = i - 2;
                    if (index < threads.size()) {
                        Thread thread = threads.get(index);
                        formatter.format(format, thread.getId(), thread.getState().name(), thread.getName(), thread.getThreadGroup().getName());
                    }
                }
            }
            process.write(buf.toString());
        });
        // Terminate when user hits Ctrl-C
        process.interruptHandler(v -> {
            vertx.cancelTimer(id);
            process.end();
        });
    }).build(vertx);
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    CommandRegistry.getShared(vertx).registerCommand(starwars);
    service.start(ar -> {
        if (!ar.succeeded()) {
            ar.cause().printStackTrace();
        }
    });
}
Also used : TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) List(java.util.List) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) CommandRegistry(io.vertx.ext.shell.command.CommandRegistry) AbstractVerticle(io.vertx.core.AbstractVerticle) ShellService(io.vertx.ext.shell.ShellService) CommandBuilder(io.vertx.ext.shell.command.CommandBuilder) Runner(io.vertx.example.util.Runner) ArrayList(java.util.ArrayList) Formatter(java.util.Formatter) ShellService(io.vertx.ext.shell.ShellService) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) Formatter(java.util.Formatter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with ShellServiceOptions

use of io.vertx.ext.shell.ShellServiceOptions in project vertx-examples by vert-x3.

the class StarwarsCommand method start.

@Override
public void start() throws Exception {
    Command starwars = CommandBuilder.command("starwars").processHandler(process -> {
        // Connect the client
        NetClient client = process.vertx().createNetClient();
        client.connect(23, "towel.blinkenlights.nl", ar -> {
            if (ar.succeeded()) {
                NetSocket socket = ar.result();
                // Ctrl-C closes the socket
                process.interruptHandler(v -> {
                    socket.close();
                });
                // 
                socket.handler(buff -> {
                    // Push the data to the Shell
                    process.write(buff.toString("UTF-8"));
                }).exceptionHandler(err -> {
                    err.printStackTrace();
                    socket.close();
                });
                // When socket closes, end the command
                socket.closeHandler(v -> {
                    process.end();
                });
            } else {
                process.write("Could not connect to remote Starwars server\n").end();
            }
        });
    }).build(vertx);
    ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions(new TelnetTermOptions().setHost("localhost").setPort(3000)));
    CommandRegistry.getShared(vertx).registerCommand(starwars);
    service.start(ar -> {
        if (!ar.succeeded()) {
            ar.cause().printStackTrace();
        }
    });
}
Also used : TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions) CommandRegistry(io.vertx.ext.shell.command.CommandRegistry) AbstractVerticle(io.vertx.core.AbstractVerticle) ShellService(io.vertx.ext.shell.ShellService) CommandBuilder(io.vertx.ext.shell.command.CommandBuilder) NetClient(io.vertx.core.net.NetClient) Runner(io.vertx.example.util.Runner) NetSocket(io.vertx.core.net.NetSocket) NetSocket(io.vertx.core.net.NetSocket) ShellService(io.vertx.ext.shell.ShellService) NetClient(io.vertx.core.net.NetClient) TelnetTermOptions(io.vertx.ext.shell.term.TelnetTermOptions) Command(io.vertx.ext.shell.command.Command) ShellServiceOptions(io.vertx.ext.shell.ShellServiceOptions)

Aggregations

ShellService (io.vertx.ext.shell.ShellService)10 ShellServiceOptions (io.vertx.ext.shell.ShellServiceOptions)10 TelnetTermOptions (io.vertx.ext.shell.term.TelnetTermOptions)6 AbstractVerticle (io.vertx.core.AbstractVerticle)5 Runner (io.vertx.example.util.Runner)5 Command (io.vertx.ext.shell.command.Command)5 CommandBuilder (io.vertx.ext.shell.command.CommandBuilder)5 CommandRegistry (io.vertx.ext.shell.command.CommandRegistry)5 JsonObject (io.vertx.core.json.JsonObject)4 ShiroAuthOptions (io.vertx.ext.auth.shiro.ShiroAuthOptions)4 JksOptions (io.vertx.core.net.JksOptions)2 HttpTermOptions (io.vertx.ext.shell.term.HttpTermOptions)2 SSHTermOptions (io.vertx.ext.shell.term.SSHTermOptions)2 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2 List (java.util.List)2 Argument (io.vertx.core.cli.Argument)1 CLI (io.vertx.core.cli.CLI)1 HttpClient (io.vertx.core.http.HttpClient)1 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1