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); } }
line.wordIndex(), 0, line.cursor(), cs); for(CharSequence c: cs){
@Override public int getBufferPosition() { return line.cursor(); }
@Override public int getBufferPosition() { return line.cursor(); }
public int cursor() { return line.cursor(); } public CharSequence escape(CharSequence candidate, boolean complete) {
@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); } } }