use of org.jline.reader.Completer in project nifi by apache.
the class CLIMain method runInteractiveCLI.
/**
* Runs the interactive CLI.
*
* @throws IOException if an error occurs
*/
private static void runInteractiveCLI() throws IOException {
// Logger.getLogger("org.jline").setLevel(Level.FINE);
try (final Terminal terminal = TerminalBuilder.builder().name(SHELL_NAME).system(true).nativeSignals(true).signalHandler(Terminal.SignalHandler.SIG_IGN).build();
final PrintStream output = new PrintStream(terminal.output(), true)) {
printHeader(BANNER_FILE, output);
final Context context = createContext(output, true);
final Map<String, Command> topLevelCommands = CommandFactory.createTopLevelCommands(context);
final Map<String, CommandGroup> commandGroups = CommandFactory.createCommandGroups(context);
final CommandProcessor commandProcessor = new CommandProcessor(topLevelCommands, commandGroups, context);
final Completer completer = new CLICompleter(topLevelCommands.values(), commandGroups.values());
final LineReader reader = LineReaderBuilder.builder().appName(SHELL_NAME).terminal(terminal).completer(completer).build();
reader.setOpt(LineReader.Option.AUTO_FRESH_LINE);
reader.unsetOpt(LineReader.Option.INSERT_TAB);
while (true) {
try {
final String line = reader.readLine(PROMPT);
if (StringUtils.isBlank(line)) {
continue;
}
final ParsedLine parsedLine = reader.getParsedLine();
final String[] parsedArgs = parsedLine.words().toArray(new String[parsedLine.words().size()]);
commandProcessor.process(parsedArgs);
} catch (UserInterruptException e) {
// Ignore
} catch (EndOfFileException e) {
return;
}
}
}
}
Aggregations