@Override public ParsedLine parse(final String line, final int cursor, final ParseContext context) { final ParsedLine parsed = delegate.parse(line, cursor, context); if (context != ParseContext.ACCEPT_LINE) { return parsed; } final String bare = CommentStripper.strip(parsed.line()); if (bare.isEmpty()) { return parsed; } if (cliCmdPredicate.test(bare)) { return parsed; } if (!bare.endsWith(TERMINATION_CHAR)) { throw new EOFError(-1, -1, "Missing termination char", "termination char"); } return parsed; } }
Objects.requireNonNull(candidates); if (line.wordIndex() < 0) { return; if (line.wordIndex() == 0) { addCandidates(topLevelCommandMap.keySet(), candidates); return; if (line.wordIndex() == 1) { final String firstLevel = line.words().get(0); if (line.wordIndex() >= 2) { final String firstLevel = line.words().get(0); final String secondLevel = line.words().get(1); if (line.wordIndex() == 2) { addCandidates(SessionVariable.getAllVariableNames(), candidates); } else if (line.wordIndex() == 3) { final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1); if (FILE_COMPLETION_VARS.contains(prevWord)) { final Completers.FileNameCompleter fileNameCompleter = new Completers.FileNameCompleter(); final String currWord = line.word(); final String prevWord = line.words().get(line.wordIndex() - 1);
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) { String statement = line.line(); // remove ';' at the end if (statement.endsWith(";")) { statement = statement.substring(0, statement.length() - 1); } // handle SQL client specific commands final String statementNormalized = statement.toUpperCase().trim(); for (String commandHint : COMMAND_HINTS) { if (commandHint.startsWith(statementNormalized) && line.cursor() < commandHint.length()) { candidates.add(createCandidate(commandHint)); } } // fallback to Table API hinting try { executor.completeStatement(context, statement, line.cursor()) .forEach(hint -> candidates.add(createCandidate(hint))); } catch (SqlExecutionException e) { LOG.debug("Could not complete statement at " + line.cursor() + ":" + statement, e); } }
@Override public synchronized void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) { List<String> words = line.words().subList(0, line.wordIndex()); this.reader.set(reader); Set<String> next = matcher.matchPartial(words); for (String n : next) { completers.apply(n).complete(reader, new ArgumentLine(line.word(), line.wordCursor()), candidates); } this.reader.set(null); }
@Override public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) { CompletingParsedLine cpl = (line instanceof CompletingParsedLine) ? ((CompletingParsedLine) line) : t -> t; CompletionContext context = new CompletionContext(sanitizeInput(line.words()), line.wordIndex(), line.wordCursor()); List<CompletionProposal> proposals = shell.complete(context); proposals.stream() .map(p -> new Candidate( p.dontQuote() ? p.value() : cpl.emit(p.value()).toString(), p.displayText(), p.category(), p.description(), null, null, true) ) .forEach(candidates::add); }
@Override public int getCursorArgumentIndex() { return line.wordIndex(); }
assert candidates != null; String buffer = commandLine.word().substring(0, commandLine.wordCursor());
Objects.requireNonNull(candidates); if (line.wordIndex() < 0) { return; if (line.wordIndex() >= completers.size()) { completer = completers.get(completers.size() - 1); completer = completers.get(line.wordIndex()); for (int i = 0; isStrict() && (i < line.wordIndex()); i++) { Completer sub = completers.get(i >= completers.size() ? (completers.size() - 1) : i); List<? extends CharSequence> args = line.words(); String arg = (args == null || i >= args.size()) ? "" : args.get(i).toString();
query.append('\n'); query.append(line); } else if ("load".equals(pl.word())) { if (pl.words().size() == 2 || pl.words().size() == 3 || pl.words().size() == 4) { String[] splits = line.split("\\s"); String fName = splits[1]; if (pl.words().size() > 2) { try { threadCount = Integer.parseInt(pl.words().get(2)); } catch (NumberFormatException ex) { encoding = pl.words().get(2); if (pl.words().size() == 4) { encoding = pl.words().get(3); } else if ("get".equals(pl.word())) { if (pl.words().size() == 2) { String uri = pl.words().get(1); String content = client.getDocument(uri); if (content != null) { } else if ("query".equals(pl.word())) { query = new StringBuffer(line); query.delete(0, 6); querying = true; } else if ("remove".equals(pl.word())) {
@Override public String getCursorArgument() { return line.word(); }
@Override public int getBufferPosition() { return line.cursor(); }
@Override public int getArgumentPosition() { return line.wordCursor(); }
@Override public synchronized void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) { List<String> words = line.words().subList(0, line.wordIndex()); this.reader.set(reader); Set<String> next = matcher.matchPartial(words); for (String n : next) { completers.apply(n).complete(reader, new ArgumentLine(line.word(), line.wordCursor()), candidates); } this.reader.set(null); }
line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null); ParsedLine pl = reader.getParser().parse(line, 0); String[] arguments = pl.words().toArray(new String[0]); CommandLine.run(commands, arguments); } catch (UserInterruptException e) {
@Override public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) { try { String buffer = line.line(); if (StringUtils.isEmpty(buffer) || buffer.indexOf(' ') == -1) { completeCommandName(buffer, candidates); } int separatorPos = buffer.indexOf(' '); String commandName = buffer.substring(0, separatorPos); if (LOG.isDebugEnabled()) { LOG.debug("Command name is [" + commandName + "]"); } String commandArguments = buffer.substring(separatorPos + 1); commandArguments.replaceFirst("^\\s*", ""); if (LOG.isDebugEnabled()) { LOG.debug("Analyzing commmand arguments [" + commandArguments + "]"); } Command cmd = commandCenter.commandFactory.createCommand(commandName); cmd.setSession(commandCenter.session); CliCompletor commandCompletor = new CliCompletor(cmd, commandCenter.argTokenizer); int position = line.cursor(); commandCompletor.complete(reader, new ArgumentCompleter.ArgumentLine(commandArguments, position - separatorPos), candidates); } catch (RuntimeException e) { if (LOG.isDebugEnabled()) { LOG.debug("Couldn't complete input", e); } } }
@Override public int getCursorArgumentIndex() { return line.wordIndex(); }