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