Java Code Examples for org.jline.reader.impl.completer.StringsCompleter
The following examples show how to use
org.jline.reader.impl.completer.StringsCompleter. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xraft Source File: Console.java License: MIT License | 6 votes |
public Console(Map<NodeId, Address> serverMap) { commandMap = buildCommandMap(Arrays.asList( new ExitCommand(), new ClientAddServerCommand(), new ClientRemoveServerCommand(), new ClientListServerCommand(), new ClientGetLeaderCommand(), new ClientSetLeaderCommand(), new RaftAddNodeCommand(), new RaftRemoveNodeCommand(), new KVStoreGetCommand(), new KVStoreSetCommand() )); commandContext = new CommandContext(serverMap); ArgumentCompleter completer = new ArgumentCompleter( new StringsCompleter(commandMap.keySet()), new NullCompleter() ); reader = LineReaderBuilder.builder() .completer(completer) .build(); }
Example 2
Source Project: super-cloudops Source File: DynamicCompleter.java License: Apache License 2.0 | 6 votes |
@Override public void complete(LineReader reader, ParsedLine parsedLine, List<Candidate> candidates) { List<String> commands = LineUtils.parse(parsedLine.line()); // Primary level frist arguments if (commands.isEmpty()) { new StringsCompleter(registry.getHelpOptions().keySet()).complete(reader, parsedLine, candidates); } // Secondary primary arguments else { HelpOptions options = registry.getHelpOptions().get(commands.get(0)); // Continue before completion if (completingCompleted(commands, options)) { List<String> candes = new ArrayList<>(); for (Option opt : options.getOptions()) { candes.add(GNU_CMD_SHORT + opt.getOpt()); candes.add(GNU_CMD_LONG + opt.getLongOpt()); } new StringsCompleter(candes).complete(reader, parsedLine, candidates); } } }
Example 3
Source Project: Bats Source File: DrillSqlLineApplication.java License: Apache License 2.0 | 5 votes |
@Override public Collection<CommandHandler> getCommandHandlers(SqlLine sqlLine) { List<String> commandsToExclude = new ArrayList<>(); // exclude connect command and then add it back to ensure connection url examples are updated boolean reloadConnect = config.hasPath(CONNECTION_URL_EXAMPLES_CONF); if (reloadConnect) { commandsToExclude.add("connect"); } if (config.hasPath(COMMANDS_TO_EXCLUDE_CONF)) { commandsToExclude.addAll(config.getStringList(COMMANDS_TO_EXCLUDE_CONF)); } if (commandsToExclude.isEmpty()) { return sqlLine.getCommandHandlers(); } List<CommandHandler> commandHandlers = sqlLine.getCommandHandlers().stream() .filter(c -> c.getNames().stream() .noneMatch(commandsToExclude::contains)) .collect(Collectors.toList()); if (reloadConnect) { commandHandlers.add(new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getConnectionUrlExamples()), "connect", "open")); } return commandHandlers; }
Example 4
Source Project: presto Source File: Completion.java License: Apache License 2.0 | 5 votes |
public static Completer commandCompleter() { return new StringsCompleter(ImmutableSet.<String>builder() .addAll(COMMANDS) .addAll(COMMANDS.stream() .map(value -> value.toLowerCase(ENGLISH)) .collect(toSet())) .build()); }
Example 5
Source Project: Lealone-Plugins Source File: SqlLineApplication.java License: Apache License 2.0 | 5 votes |
@Override public Collection<CommandHandler> getCommandHandlers(SqlLine sqlLine) { List<String> commandsToExclude = new ArrayList<>(); // exclude connect command and then add it back to ensure connection url examples are updated boolean reloadConnect = config.hasPath(CONNECTION_URL_EXAMPLES_CONF); if (reloadConnect) { commandsToExclude.add("connect"); } if (config.hasPath(COMMANDS_TO_EXCLUDE_CONF)) { commandsToExclude.addAll(config.getStringList(COMMANDS_TO_EXCLUDE_CONF)); } if (commandsToExclude.isEmpty()) { return sqlLine.getCommandHandlers(); } List<CommandHandler> commandHandlers = sqlLine.getCommandHandlers().stream() .filter(c -> c.getNames().stream().noneMatch(commandsToExclude::contains)).collect(Collectors.toList()); if (reloadConnect) { commandHandlers.add(new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getConnectionUrlExamples()), "connect", "open")); } return commandHandlers; }
Example 6
Source Project: sqlline Source File: SqlLineOpts.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void complete(LineReader lineReader, ParsedLine parsedLine, List<Candidate> list) { try { new StringsCompleter(propertyNames()) .complete(lineReader, parsedLine, list); } catch (Throwable ignored) { } }
Example 7
Source Project: sqlline Source File: SqlLineCommandCompleter.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
SqlLineCommandCompleter(SqlLine sqlLine) { super(new LinkedList<>()); List<Completer> completers = new LinkedList<>(); for (CommandHandler commandHandler : sqlLine.getCommandHandlers()) { for (String cmd : commandHandler.getNames()) { List<Completer> compl = new LinkedList<>(); final List<Completer> parameterCompleters = commandHandler.getParameterCompleters(); if (parameterCompleters.size() == 1 && parameterCompleters.iterator().next() instanceof Completers.RegexCompleter) { completers.add(parameterCompleters.iterator().next()); } else { final String commandName = SqlLine.COMMAND_PREFIX + cmd; final String helpText = commandHandler.getHelpText(); final int firstEndOfLineIndex = helpText.indexOf('\n'); compl.add( new StringsCompleter( new SqlLineCandidate(sqlLine, AttributedString.stripAnsi(commandName), commandName, sqlLine.loc("command-name"), firstEndOfLineIndex == -1 ? helpText : helpText.substring(0, firstEndOfLineIndex), // there could be whatever else instead helpText // which is the same for commands with all theirs aliases null, helpText, true))); compl.addAll(parameterCompleters); compl.add(new NullCompleter()); // last param no complete completers.add(new ArgumentCompleter(compl)); } } } getCompleters().addAll(completers); }
Example 8
Source Project: sqlline Source File: TableNameCompleter.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void complete(LineReader lineReader, ParsedLine parsedLine, List<Candidate> list) { if (sqlLine.getDatabaseConnection() == null) { return; } new StringsCompleter(sqlLine.getDatabaseConnection().getTableNames(true)) .complete(lineReader, parsedLine, list); }
Example 9
Source Project: sqlline Source File: CustomApplication.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Collection<CommandHandler> getCommandHandlers( SqlLine sqlLine) { final List<CommandHandler> commandHandlers = new ArrayList<>(sqlLine.getCommandHandlers()); final Iterator<CommandHandler> iterator = commandHandlers.iterator(); while (iterator.hasNext()) { CommandHandler next = iterator.next(); List<String> names = next.getNames(); if (names.contains("tables") || names.contains("connect") || names.contains("outputformat")) { iterator.remove(); } } commandHandlers.add( new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getConnectionUrlExamples()), "connect", "open")); commandHandlers.add( new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getOutputFormats(sqlLine).keySet()), "outputformat")); return commandHandlers; }
Example 10
Source Project: samza Source File: CliShell.java License: Apache License 2.0 | 4 votes |
CliShell(CliEnvironment environment) throws ExecutorException { if (environment == null) { throw new IllegalArgumentException(); } // Terminal try { terminal = TerminalBuilder.builder().name(CliConstants.WINDOW_TITLE).build(); } catch (IOException e) { throw new CliException("Error when creating terminal", e); } // Terminal writer writer = terminal.writer(); // LineReader final DefaultParser parser = new DefaultParser().eofOnEscapedNewLine(true).eofOnUnclosedQuote(true); lineReader = LineReaderBuilder.builder() .appName(CliConstants.APP_NAME) .terminal(terminal) .parser(parser) .highlighter(new CliHighlighter()) .completer(new StringsCompleter(CliCommandType.getAllCommands())) .build(); // Command Prompt firstPrompt = new AttributedStringBuilder().style(AttributedStyle.DEFAULT.foreground(AttributedStyle.YELLOW)) .append(CliConstants.PROMPT_1ST + CliConstants.PROMPT_1ST_END) .toAnsi(); // Execution context and executor executor = environment.getExecutor(); exeContext = new ExecutionContext(); executor.start(exeContext); // Command handlers if (commandHandlers == null) { commandHandlers = new ArrayList<>(); } commandHandlers.add(new CliCommandHandler()); commandHandlers.addAll(environment.getCommandHandlers()); for (CommandHandler commandHandler : commandHandlers) { LOG.info("init commandHandler {}", commandHandler.getClass().getName()); commandHandler.init(this, environment, terminal, exeContext); } }
Example 11
Source Project: sqlline Source File: Application.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Override this method to modify supported commands. * * <p>If method is not overridden, current state of commands will be * reset to default ({@code super.getCommandHandlers(sqlLine)}). * * <p>To update / leave current state, override this method * and use {@code sqlLine.getCommandHandlers()}. * * @param sqlLine SQLLine instance * * @return Collection of command handlers */ public Collection<CommandHandler> getCommandHandlers(SqlLine sqlLine) { TableNameCompleter tableCompleter = new TableNameCompleter(sqlLine); List<Completer> empty = Collections.emptyList(); final Map<String, OutputFormat> outputFormats = getOutputFormats(sqlLine); final Map<BuiltInProperty, Collection<String>> customPropertyCompletions = new HashMap<>(); customPropertyCompletions .put(BuiltInProperty.OUTPUT_FORMAT, outputFormats.keySet()); final CommandHandler[] handlers = { new ReflectiveCommandHandler(sqlLine, empty, "quit", "done", "exit"), new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getConnectionUrlExamples()), "connect", "open"), new ReflectiveCommandHandler(sqlLine, empty, "nickname"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "describe"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "indexes"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "primarykeys"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "exportedkeys"), new ReflectiveCommandHandler(sqlLine, empty, "manual"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "importedkeys"), new ReflectiveCommandHandler(sqlLine, empty, "procedures"), new ReflectiveCommandHandler(sqlLine, empty, "schemas"), new ReflectiveCommandHandler(sqlLine, empty, "tables"), new ReflectiveCommandHandler(sqlLine, empty, "typeinfo"), new ReflectiveCommandHandler(sqlLine, empty, "commandhandler"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "columns"), new ReflectiveCommandHandler(sqlLine, empty, "reconnect"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "dropall"), new ReflectiveCommandHandler(sqlLine, empty, "history"), new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getMetadataMethodNames()), "metadata"), new ReflectiveCommandHandler(sqlLine, empty, "nativesql"), new ReflectiveCommandHandler(sqlLine, empty, "dbinfo"), new ReflectiveCommandHandler(sqlLine, empty, "rehash"), new ReflectiveCommandHandler(sqlLine, empty, "resize"), new ReflectiveCommandHandler(sqlLine, empty, "verbose"), new ReflectiveCommandHandler(sqlLine, new FileNameCompleter(), "run"), new ReflectiveCommandHandler(sqlLine, empty, "batch"), new ReflectiveCommandHandler(sqlLine, empty, "list"), new ReflectiveCommandHandler(sqlLine, empty, "all"), new ReflectiveCommandHandler(sqlLine, new ConnectionCompleter(sqlLine), "go", "#"), new ReflectiveCommandHandler(sqlLine, new FileNameCompleter(), "script") { @Override public boolean echoToFile() { return false; } }, new ReflectiveCommandHandler(sqlLine, new FileNameCompleter(), "record"), new ReflectiveCommandHandler(sqlLine, empty, "brief"), new ReflectiveCommandHandler(sqlLine, empty, "close"), new ReflectiveCommandHandler(sqlLine, empty, "closeall"), new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getIsolationLevels()), "isolation"), new ReflectiveCommandHandler(sqlLine, new StringsCompleter(outputFormats.keySet()), "outputformat"), new ReflectiveCommandHandler(sqlLine, empty, "autocommit"), new ReflectiveCommandHandler(sqlLine, empty, "readonly"), new ReflectiveCommandHandler(sqlLine, empty, "commit"), new ReflectiveCommandHandler(sqlLine, new FileNameCompleter(), "properties"), new ReflectiveCommandHandler(sqlLine, empty, "rollback"), new ReflectiveCommandHandler(sqlLine, empty, "help", "?"), new ReflectiveCommandHandler(sqlLine, getOpts(sqlLine).setOptionCompleters(customPropertyCompletions), "set"), new ReflectiveCommandHandler(sqlLine, getOpts(sqlLine).resetOptionCompleters(), "reset"), new ReflectiveCommandHandler(sqlLine, empty, "save"), new ReflectiveCommandHandler(sqlLine, empty, "scan"), new ReflectiveCommandHandler(sqlLine, empty, "sql"), new ReflectiveCommandHandler(sqlLine, empty, "call"), new ReflectiveCommandHandler(sqlLine, empty, "appconfig"), new ReflectiveCommandHandler(sqlLine, empty, "rerun", "/"), new ReflectiveCommandHandler(sqlLine, empty, "prompthandler"), }; return Collections.unmodifiableList(Arrays.asList(handlers)); }