org.jline.reader.impl.completer.ArgumentCompleter Java Examples

The following examples show how to use org.jline.reader.impl.completer.ArgumentCompleter. 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 File:    From xraft with MIT License 6 votes vote down vote up
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()
Example #2
Source File:    From sqlline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 =
      if (parameterCompleters.size() == 1
          && parameterCompleters.iterator().next()
              instanceof Completers.RegexCompleter) {
      } else {
        final String commandName = SqlLine.COMMAND_PREFIX + cmd;
        final String helpText = commandHandler.getHelpText();
        final int firstEndOfLineIndex = helpText.indexOf('\n');
            new StringsCompleter(
                new SqlLineCandidate(sqlLine,
                    AttributedString.stripAnsi(commandName), commandName,
                    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.add(new NullCompleter()); // last param no complete
        completers.add(new ArgumentCompleter(compl));

Example #3
Source File:    From ssh-shell-spring-boot with Apache License 2.0 4 votes vote down vote up
private void setAnswer(String answer) {
    when(lr.getParsedLine()).thenReturn(new ArgumentCompleter.ArgumentLine(answer, 0));
Example #4
Source File:    From batfish with Apache License 2.0 4 votes vote down vote up
public Client(Settings settings) {
  _additionalBatfishOptions = new HashMap<>();
  _bfq = new TreeMap<>();
  _settings = settings;

  switch (_settings.getRunMode()) {
    case batch:
      if (_settings.getBatchCommandFile() == null) {
            "org.batfish.client: Command file not specified while running in batch mode.");
            "Use '-%s <cmdfile>' if you want batch mode, or '-%s interactive' if you want "
                + "interactive mode\n",
            Settings.ARG_COMMAND_FILE, Settings.ARG_RUN_MODE);
      _logger = new BatfishLogger(_settings.getLogLevel(), false, _settings.getLogFile());
    case interactive:
          "This is not a supported client for Batfish. Please use pybatfish following the "
              + "instructions in the README:");
      try {
        _reader =
                .completer(new ArgumentCompleter(new CommandCompleter(), new NullCompleter()))
        Path historyPath = Paths.get(System.getenv(ENV_HOME), HISTORY_FILE);
        _reader.setVariable(LineReader.HISTORY_FILE, historyPath.toAbsolutePath().toString());
        _reader.unsetOpt(Option.INSERT_TAB); // supports completion with nothing entered

        @SuppressWarnings("PMD.CloseResource") // PMD does not understand things closed later.
        PrintWriter pWriter = new PrintWriter(_reader.getTerminal().output(), true);
        @SuppressWarnings("PMD.CloseResource") // PMD does not understand things closed later.
        OutputStream os = new WriterOutputStream(pWriter, StandardCharsets.UTF_8);
        @SuppressWarnings("PMD.CloseResource") // PMD does not understand things closed later.
        PrintStream ps = new PrintStream(os, true);
        _logger = new BatfishLogger(_settings.getLogLevel(), false, ps);
      } catch (Exception e) {
        System.err.printf("Could not initialize client: %s\n", e.getMessage());
      System.err.println("org.batfish.client: Unknown run mode.");
Example #5
Source File:    From sqlline with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void setCompletions(boolean skipmeta) {
  // setup the completer for the database
  sqlCompleter = new ArgumentCompleter(new SqlCompleter(sqlLine, skipmeta));
  // not all argument elements need to hold true
  ((ArgumentCompleter) sqlCompleter).setStrict(false);