Search in sources :

Example 1 with AggregateCompleter

use of jline.console.completer.AggregateCompleter in project hive by apache.

the class BeeLineCommandCompleter method getCompleters.

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()));
                // last param no complete
                compl.add(new NullCompleter());
                completers.add(new AggregateCompleter(compl.toArray(new Completer[compl.size()])));
            }
        }
    }
    return completers;
}
Also used : NullCompleter(jline.console.completer.NullCompleter) StringsCompleter(jline.console.completer.StringsCompleter) AggregateCompleter(jline.console.completer.AggregateCompleter) Completer(jline.console.completer.Completer) AggregateCompleter(jline.console.completer.AggregateCompleter) StringsCompleter(jline.console.completer.StringsCompleter) NullCompleter(jline.console.completer.NullCompleter) LinkedList(java.util.LinkedList)

Example 2 with AggregateCompleter

use of jline.console.completer.AggregateCompleter in project GeoGig by boundlessgeo.

the class GeogigConsole method addCommandCompleter.

private void addCommandCompleter(ConsoleReader consoleReader, final GeogigCLI cli) {
    final JCommander globalCommandParser = cli.newCommandParser();
    final Map<String, JCommander> commands = globalCommandParser.getCommands();
    List<Completer> completers = new ArrayList<Completer>(commands.size());
    for (Map.Entry<String, JCommander> entry : commands.entrySet()) {
        String commandName = entry.getKey();
        JCommander commandParser = entry.getValue();
        List<ParameterDescription> parameters = commandParser.getParameters();
        List<String> options = new ArrayList<String>(parameters.size());
        for (ParameterDescription pd : parameters) {
            String longestName = pd.getLongestName();
            options.add(longestName);
        }
        Collections.sort(options);
        ArgumentCompleter commandCompleter = new ArgumentCompleter(new StringsCompleter(commandName), new StringsCompleter(options));
        completers.add(commandCompleter);
    }
    completers.add(new StringsCompleter("exit", "clear"));
    Completer completer = new AggregateCompleter(completers);
    consoleReader.addCompleter(completer);
}
Also used : ArgumentCompleter(jline.console.completer.ArgumentCompleter) AggregateCompleter(jline.console.completer.AggregateCompleter) ArrayList(java.util.ArrayList) Completer(jline.console.completer.Completer) StringsCompleter(jline.console.completer.StringsCompleter) AggregateCompleter(jline.console.completer.AggregateCompleter) ArgumentCompleter(jline.console.completer.ArgumentCompleter) StringsCompleter(jline.console.completer.StringsCompleter) JCommander(com.beust.jcommander.JCommander) Map(java.util.Map) ParameterDescription(com.beust.jcommander.ParameterDescription)

Aggregations

AggregateCompleter (jline.console.completer.AggregateCompleter)2 Completer (jline.console.completer.Completer)2 StringsCompleter (jline.console.completer.StringsCompleter)2 JCommander (com.beust.jcommander.JCommander)1 ParameterDescription (com.beust.jcommander.ParameterDescription)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 ArgumentCompleter (jline.console.completer.ArgumentCompleter)1 NullCompleter (jline.console.completer.NullCompleter)1