@ShellMethod(value = "Read and execute commands from a file.") public void script(File file) throws IOException { Reader reader = new FileReader(file); try (FileInputProvider inputProvider = new FileInputProvider(reader, parser)) { shell.run(inputProvider); } }
@Override public void run(ApplicationArguments args) throws Exception { List<File> scriptsToRun = args.getNonOptionArgs().stream() .filter(s -> s.startsWith("@")) .map(s -> new File(s.substring(1))) .collect(Collectors.toList()); boolean batchEnabled = environment.getProperty(SPRING_SHELL_SCRIPT_ENABLED, boolean.class, true); if (!scriptsToRun.isEmpty() && batchEnabled) { InteractiveShellApplicationRunner.disable(environment); for (File file : scriptsToRun) { try (Reader reader = new FileReader(file); FileInputProvider inputProvider = new FileInputProvider(reader, parser)) { shell.run(inputProvider); } } } } //end::documentation[]
@Override public void run(ApplicationArguments args) throws Exception { boolean interactive = isEnabled(); if (interactive) { InputProvider inputProvider = new JLineInputProvider(lineReader, promptProvider); shell.run(inputProvider); } }
@Override public void run(ApplicationArguments args) throws Exception { // if we have args, assume one time run ArrayList<String> argsToShellCommand = new ArrayList<>(); for (String arg : args.getSourceArgs()) { // consider client connection options as non command args if (!arg.contains("spring.cloud.skipper.client")) { argsToShellCommand.add(arg); } } if (argsToShellCommand.size() > 0) { if (ShellUtils.hasHelpOption(args)) { // going into 'help' mode. HelpAwareShellApplicationRunner already // printed usage, we just force running just help. argsToShellCommand.clear(); argsToShellCommand.add("help"); } } if (!argsToShellCommand.isEmpty()) { InteractiveShellApplicationRunner.disable(environment); shell.run(new StringInputProvider(argsToShellCommand)); } }
@Override public void run() { Terminal terminal; try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos, true, "utf-8")) { terminal = TerminalBuilder.builder().system(false).type(terminalType).streams(is, os).build(); DefaultResultHandler resultHandler = new DefaultResultHandler(); resultHandler.setTerminal(terminal); shellBanner.printBanner(environment, this.getClass(), ps); resultHandler.handleResult(new String(baos.toByteArray(), StandardCharsets.UTF_8)); resultHandler.handleResult("Please type `help` to see available commands"); LineReader reader = LineReaderBuilder.builder().terminal(terminal).completer(completerAdapter).build(); InputProvider inputProvider = new InteractiveShellApplicationRunner.JLineInputProvider(reader, promptProvider); THREAD_CONTEXT.set(new SshContext(terminal, ec, sshThread)); if (terminalDelegate instanceof SshShellTerminalDelegate) { ((SshShellTerminalDelegate) terminalDelegate).setDelegate(terminal); } shell.run(inputProvider); quit(0); } catch (IOException | RuntimeException e) { // log ex quit(1); } }
shell.run(new SshShellInputProvider(reader, promptProvider)); LOGGER.debug("{}: end", session.toString()); quit(0);