Search in sources :

Example 6 with StringsCompleter

use of jline.console.completer.StringsCompleter 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

StringsCompleter (jline.console.completer.StringsCompleter)6 Completer (jline.console.completer.Completer)4 AggregateCompleter (jline.console.completer.AggregateCompleter)3 ArgumentCompleter (jline.console.completer.ArgumentCompleter)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 JCommander (com.beust.jcommander.JCommander)1 ParameterDescription (com.beust.jcommander.ParameterDescription)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 AbstractArgumentDelimiter (jline.console.completer.ArgumentCompleter.AbstractArgumentDelimiter)1 ArgumentDelimiter (jline.console.completer.ArgumentCompleter.ArgumentDelimiter)1 FileNameCompleter (jline.console.completer.FileNameCompleter)1 NullCompleter (jline.console.completer.NullCompleter)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 ConfVars (org.apache.hadoop.hive.conf.HiveConf.ConfVars)1