@Override public int execute(ConsoleOperation output) throws InterruptedException { // grab the user the input String expression = StringUtils.trimToEmpty(output.getBuffer()); if(StringUtils.isNotBlank(expression) ) { // execute the expression StellarResult result = executor.execute(expression); if(result.isSuccess()) { // on success result.getValue().ifPresent(v -> writeLine(v.toString())); } else if (result.isError()) { // on error result.getException().ifPresent(e -> writeLine(ERROR_PROMPT + e.getMessage())); result.getException().ifPresent(e -> e.printStackTrace()); } else if(result.isTerminate()) { // on quit handleQuit(); } else { // should never happen throw new IllegalStateException("An execution result is neither a success nor a failure. Please file a bug report."); } } return 0; }
private CommandContainer getCommand(ConsoleOperation output, AeshLine aeshLine) throws CommandNotFoundException { Method m; try { m = console.getClass().getDeclaredMethod("getCommand", AeshLine.class, String.class); } catch (NoSuchMethodException e) { throw new RuntimeException("Unexpected error: ", e); } m.setAccessible(true); try { return (CommandContainer) m.invoke(console, aeshLine, output.getBuffer()); } catch (Exception e) { throw new RuntimeException("Unexpected error: ", e); } } }
private CommandContainer getCommand(ConsoleOperation output, AeshLine aeshLine) throws CommandNotFoundException { Method m; try { m = console.getClass().getDeclaredMethod("getCommand", AeshLine.class, String.class); } catch (NoSuchMethodException e) { throw new RuntimeException("Unexpected error: ", e); } m.setAccessible(true); try { return (CommandContainer) m.invoke(console, aeshLine, output.getBuffer()); } catch (Exception e) { throw new RuntimeException("Unexpected error: ", e); } } }
@Override public int execute(ConsoleOperation output) { String statement = output.getBuffer(); log.write(statement + "\n"); if (statement.equalsIgnoreCase("exit")) { console.stop(); return 0; } else { try { Object object = runtime.evaluate(statement); log.write(object.toString() + "\n"); console.getShell().out().println(object.toString()); } catch (DynJSException e) { console.getShell().out().println(e.getLocalizedMessage()); logException(e); } catch (IncompatibleClassChangeError e) { console.getShell().err().println("ERROR> " + e.getLocalizedMessage()); console.getShell().err().println("Error parsing statement: " + statement); logException(e); } catch (Exception e) { e.printStackTrace(new PrintWriter(out)); logException(e); } } return 0; } });
@Override @SuppressWarnings("unchecked") public int execute(ConsoleOperation output) throws InterruptedException { if (output != null && output.getBuffer().trim().length() > 0) { ResultHandler resultHandler = null; AeshLine aeshLine = new AeshLine(output.getBuffer(), Globals.args, ParserStatus.OK, ""); try (CommandContainer commandContainer = getCommand(output, aeshLine)) { resultHandler = commandContainer.getParser().getProcessedCommand().getResultHandler();
@Override @SuppressWarnings("unchecked") public int execute(ConsoleOperation output) throws InterruptedException { if (output != null && output.getBuffer().trim().length() > 0) { ResultHandler resultHandler = null; AeshLine aeshLine = new AeshLine(output.getBuffer(), Globals.args, ParserStatus.OK, ""); try (CommandContainer commandContainer = getCommand(output, aeshLine)) { resultHandler = commandContainer.getParser().getProcessedCommand().getResultHandler();