public static Completer commandCompleter() { return new StringsCompleter(COMMANDS); }
@Override public int complete(String buffer, int cursor, List<CharSequence> candidates) { // use the jline internal parser to split the line into tokens ArgumentCompleter.ArgumentList list = new ArgumentCompleter.WhitespaceArgumentDelimiter().delimit(buffer, cursor); // let picocli generate completion candidates for the token where the cursor is at return AutoComplete.complete(commandSpec, list.getArguments(), list.getCursorArgumentIndex(), list.getArgumentPosition(), cursor, candidates); } }
@Override public int complete(String buffer, int cursor, List<CharSequence> clist) { return buffer != null && buffer.equals("set") ? super.complete(buffer, cursor, clist) : -1; } };
StringsCompleter strCompleter = new StringsCompleter(candidateStrings); final ArgumentCompleter argCompleter = new ArgumentCompleter(delim, strCompleter); argCompleter.setStrict(false); StringsCompleter confCompleter = new StringsCompleter(vars) { @Override public int complete(final String buffer, final int cursor, final List<CharSequence> clist) { StringsCompleter setCompleter = new StringsCompleter("set") { @Override public int complete(String buffer, int cursor, List<CharSequence> clist) { ArgumentCompleter propCompleter = new ArgumentCompleter(setCompleter, confCompleter) { @Override public int complete(String buffer, int offset, List<CharSequence> completions) {
public static List<Completer> getCompleters(Iterable<CommandHandler> handlers){ List<Completer> completers = new LinkedList<Completer>(); for (CommandHandler handler : handlers) { String[] commandNames = handler.getNames(); if (commandNames != null) { for (String commandName : commandNames) { List<Completer> compl = new LinkedList<Completer>(); compl.add(new StringsCompleter(BeeLine.COMMAND_PREFIX + commandName)); compl.addAll(Arrays.asList(handler.getParameterCompleters())); compl.add(new NullCompleter()); // last param no complete completers.add(new AggregateCompleter(compl.toArray(new Completer[compl.size()]))); } } } return completers; } }
@Override public int complete(String buf, int pos, List cand) { try { return new StringsCompleter(propertyNames()).complete(buf, pos, cand); } catch (Exception e) { beeLine.handleException(e); return -1; } }
void setCompletions(boolean skipmeta) throws SQLException, IOException { final String extraNameCharacters = getDatabaseMetaData() == null || getDatabaseMetaData().getExtraNameCharacters() == null ? "" : getDatabaseMetaData().getExtraNameCharacters(); // setup the completer for the database sqlCompleter = new ArgumentCompleter( new ArgumentCompleter.AbstractArgumentDelimiter() { // delimiters for SQL statements are any // non-letter-or-number characters, except // underscore and characters that are specified // by the database to be valid name identifiers. @Override public boolean isDelimiterChar(CharSequence buffer, int pos) { char c = buffer.charAt(pos); if (Character.isWhitespace(c)) { return true; } return !(Character.isLetterOrDigit(c)) && c != '_' && extraNameCharacters.indexOf(c) == -1; } }, new SQLCompleter(SQLCompleter.getSQLCompleters(beeLine, skipmeta))); // not all argument elements need to hold true ((ArgumentCompleter) sqlCompleter).setStrict(false); }
public void complete(final Completer completer, final String buffer, final int cursor) { checkNotNull(completer); this.cursor = completer.complete(buffer, cursor, candidates); } }
public static void main(String[] args) { try { ConsoleReader reader = new ConsoleReader(); reader.setPrompt("prompt> "); // set up the completion CliCommands commands = new CliCommands(reader); CommandLine cmd = new CommandLine(commands); reader.addCompleter(new PicocliJLineCompleter(cmd.getCommandSpec())); // start the shell and process input until the user quits with Ctl-D String line; while ((line = reader.readLine()) != null) { ArgumentList list = new WhitespaceArgumentDelimiter().delimit(line, line.length()); CommandLine.run(commands, list.getArguments()); } } catch (Throwable t) { t.printStackTrace(); } } }
jline.console.completer.CandidateListCompletionHandler.setBuffer(reader, value, pos); String value = getUnambiguousCompletions(candidates); jline.console.completer.CandidateListCompletionHandler.setBuffer(reader, value, pos); reader.println(); jline.console.completer.CandidateListCompletionHandler.printCandidates(reader, candidates);
public AbstractCommandHandler(BeeLine beeLine, String[] names, String helpText, Completer[] completors) { this.beeLine = beeLine; name = names[0]; this.names = names; this.helpText = helpText; if (completors == null || completors.length == 0) { parameterCompleters = new Completer[] { new NullCompleter() }; } else { List<Completer> c = new LinkedList<Completer>(Arrays.asList(completors)); c.add(new NullCompleter()); parameterCompleters = c.toArray(new Completer[0]); } }
/** * Returns true if the specified character is a whitespace parameter. Check to ensure that the character is not * escaped by any of {@link #getQuoteChars}, and is not escaped by ant of the {@link #getEscapeChars}, and * returns true from {@link #isDelimiterChar}. * * @param buffer The complete command buffer * @param pos The index of the character in the buffer * @return True if the character should be a delimiter */ public boolean isDelimiter(final CharSequence buffer, final int pos) { return !isQuoted(buffer, pos) && !isEscaped(buffer, pos) && isDelimiterChar(buffer, pos); }
@Override public int complete(String buffer, int offset, List<CharSequence> completions) { int ret = super.complete(buffer, offset, completions); if (completions.size() == 1) { completions.set(0, ((String)completions.get(0)).trim()); } return ret; } };
/** * Create a new completer with the default {@link WhitespaceArgumentDelimiter}. * * @param completers The embedded completers */ public ArgumentCompleter(final Completer... completers) { this(new WhitespaceArgumentDelimiter(), completers); }
public int complete(String buf, int pos, List cand) { if (beeLine.getDatabaseConnection() == null) { return -1; } return new StringsCompleter(beeLine.getDatabaseConnection().getTableNames(true)) .complete(buf, pos, cand); } }
public static Completer lowerCaseCommandCompleter() { return new StringsCompleter(COMMANDS.stream() .map(s -> s.toLowerCase(Locale.ENGLISH)) .collect(toSet())); } }
/** * Populates the specified list with completion candidates for the specified buffer * based on the command specification that this shell was constructed with. * * @param buffer the command line string * @param cursor the position of the cursor in the command line string * @param candidates the list to populate with completion candidates that would produce * valid options, parameters or subcommands at the cursor position * in the command line * @return the cursor position in the buffer for which the completion will be relative, * or {@code -1} if no completions are found */ //@Override public int complete(String buffer, int cursor, List<CharSequence> candidates) { // use the jline internal parser to split the line into tokens ArgumentCompleter.ArgumentList list = new ArgumentCompleter.WhitespaceArgumentDelimiter().delimit(buffer, cursor); // let picocli generate completion candidates for the token where the cursor is at return AutoComplete.complete(spec, list.getArguments(), list.getCursorArgumentIndex(), list.getArgumentPosition(), cursor, candidates); } }
public int complete(String buf, int pos, List cand) { if (buf != null && buf.startsWith(BeeLine.COMMAND_PREFIX) && !buf.startsWith(BeeLine.COMMAND_PREFIX + "all") && !buf.startsWith(BeeLine.COMMAND_PREFIX + "sql")) { return beeLine.getCommandCompletor().complete(buf, pos, cand); } else { if (beeLine.getDatabaseConnection() != null && beeLine.getDatabaseConnection().getSQLCompleter() != null) { return beeLine.getDatabaseConnection().getSQLCompleter().complete(buf, pos, cand); } else { return -1; } } } }
@Override public int complete(final String buffer, final int cursor, final List<CharSequence> clist) { int result = super.complete(buffer, cursor, clist); if (clist.isEmpty() && cursor > 1 && buffer.charAt(cursor - 1) == '=') { HiveConf.ConfVars var = HiveConf.getConfVars(buffer.substring(0, cursor - 1));
@Override public int complete (String buffer, int offset, List completions) { List<String> comp = completions; int ret = argCompleter.complete(buffer, offset, completions); // ConsoleReader will do the substitution if and only if there // is exactly one valid completion, so we ignore other cases. if (completions.size() == 1) { if (comp.get(0).endsWith("( ")) { comp.set(0, comp.get(0).trim()); } } return ret; } };