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);
}
Aggregations