@Override public void start() throws Exception { Command helloWorld = CommandBuilder.command("hello-world"). processHandler(process -> { process.write("hello world\n"); process.end(); }).build(vertx); ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions( new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(helloWorld); service.start(ar -> { if (!ar.succeeded()) { ar.cause().printStackTrace(); } }); } }
@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(); } }); } }
server.registerTermServer(telnetTermServer); server.registerCommandResolver(CommandResolver.baseCommands(vertx));
/** * End the process. * @param status the exit status. */ public void end(int status) { delegate.end(status); }
/** * Set an interrupt handler, this handler is called when the command is interrupted, for instance user * press <code>Ctrl-C</code>. * @param handler the interrupt handler * @return this command */ public io.vertx.rxjava.ext.shell.command.CommandProcess interruptHandler(Handler<Void> handler) { delegate.interruptHandler(handler); return this; }
/** * Write some text to the standard output. * @param data the text * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.shell.command.CommandProcess write(String data) { delegate.write(data); return this; }
/** * @return the command name */ public String name() { String ret = delegate.name(); return ret; }
/** * Set an end handler, this handler is called when the command is ended, for instance the command is running * and the shell closes. * @param handler the end handler * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.shell.command.CommandProcess endHandler(Handler<Void> handler) { delegate.endHandler(handler); return this; }
/** * Set a suspend handler, this handler is called when the command is suspended, for instance user * press <code>Ctrl-Z</code>. * @param handler the interrupt handler * @return this command */ public io.vertx.rxjava.ext.shell.command.CommandProcess suspendHandler(Handler<Void> handler) { delegate.suspendHandler(handler); return this; }
/** * Unregister a command. * @param commandName the command name * @param completionHandler notified when the command is unregistered * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.shell.command.CommandRegistry unregisterCommand(String commandName, Handler<AsyncResult<Void>> completionHandler) { delegate.unregisterCommand(commandName, completionHandler); return this; }
/** * Set a foreground handler, this handler is called when the command is running and put to foreground. * @param handler the foreground handler * @return this command */ public io.vertx.rxjava.ext.shell.command.CommandProcess foregroundHandler(Handler<Void> handler) { delegate.foregroundHandler(handler); return this; }
/** * Set a background handler, this handler is called when the command is running and put to background. * @param handler the background handler * @return this command */ public io.vertx.rxjava.ext.shell.command.CommandProcess backgroundHandler(Handler<Void> handler) { delegate.backgroundHandler(handler); return this; }
@Override public void start() throws Exception { Command starwars = CommandBuilder.command("starwars"). processHandler(process -> { NetClient client = process.vertx().createNetClient(); client.connect(23, "towel.blinkenlights.nl", ar -> { if (ar.succeeded()) { process.interruptHandler(v -> { socket.close(); }); process.write(buff.toString("UTF-8")); }).exceptionHandler(err -> { err.printStackTrace(); process.end(); }); } else { process.write("Could not connect to remote Starwars server\n").end(); }).build(vertx); CommandRegistry.getShared(vertx).registerCommand(starwars); service.start(ar -> { if (!ar.succeeded()) {
/** * End the process with the exit status */ public void end() { delegate.end(); }
/** * Like {@link io.vertx.rxjava.ext.shell.command.CommandRegistry#unregisterCommand}, without a completion handler. * @param commandName * @return */ public io.vertx.rxjava.ext.shell.command.CommandRegistry unregisterCommand(String commandName) { delegate.unregisterCommand(commandName); return this; }
/** * Set a foreground handler, this handler is called when the command is running and put to foreground. * @param handler the foreground handler * @return this command */ public io.vertx.rxjava.ext.shell.command.CommandProcess foregroundHandler(Handler<Void> handler) { delegate.foregroundHandler(handler); return this; }
@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); for (int i = 1; i <= process.height(); i++) { process.write(buf.toString()); }); process.interruptHandler(v -> { vertx.cancelTimer(id); process.end(); }); }).build(vertx); CommandRegistry.getShared(vertx).registerCommand(starwars); service.start(ar -> { if (!ar.succeeded()) {
/** * End the process. * @param status the exit status. */ public void end(int status) { delegate.end(status); }
Command helloWorld = CommandBuilder.command(cli). processHandler(process -> { URL url; try { url = new URL(process.commandLine().getArgumentValue(0)); } catch (MalformedURLException e) { process.write("Bad url\n").end(); return; HttpClient client = process.vertx().createHttpClient(); process.write("Connecting to " + url + "\n"); int port = url.getPort(); if (port == -1) { process.write("wget: error " + err.getMessage() + "\n"); process.end(); }); req.handler(resp -> { process.write(resp.statusCode() + " " + resp.statusMessage() + "\n"); String contentType = resp.getHeader("Content-Type"); String contentLength = resp.getHeader("Content-Length"); process.write("Length: " + (contentLength != null ? contentLength : "unspecified")); if (contentType != null) { process.write("[" + contentType + "]"); process.write("\n"); process.end(); }); req.end();
/** * End the process with the exit status */ public void end() { delegate.end(); }