Search in sources :

Example 6 with ParameterDescription

use of com.beust.jcommander.ParameterDescription 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

ParameterDescription (com.beust.jcommander.ParameterDescription)6 JCommander (com.beust.jcommander.JCommander)4 ParameterException (com.beust.jcommander.ParameterException)1 Parameterized (com.beust.jcommander.Parameterized)1 Parameters (com.beust.jcommander.Parameters)1 Option (com.googlecode.jslint4java.Option)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 StringWriter (java.io.StringWriter)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Nonnull (javax.annotation.Nonnull)1 AggregateCompleter (jline.console.completer.AggregateCompleter)1 ArgumentCompleter (jline.console.completer.ArgumentCompleter)1