io.hyperfoil.cli.commands.ServerOptionCompleter Maven / Gradle / Ivy
package io.hyperfoil.cli.commands;
import java.util.function.Function;
import java.util.stream.Stream;
import org.aesh.command.completer.OptionCompleter;
import io.hyperfoil.cli.context.HyperfoilCliContext;
import io.hyperfoil.cli.context.HyperfoilCompleterData;
import io.hyperfoil.client.RestClient;
import io.hyperfoil.client.RestClientException;
public class ServerOptionCompleter implements OptionCompleter {
private final Function> provider;
public ServerOptionCompleter(Function> provider) {
this.provider = provider;
}
@Override
public void complete(HyperfoilCompleterData completerInvocation) {
HyperfoilCliContext context = completerInvocation.getContext();
if (context.client() == null) {
return;
}
Stream benchmarks;
try {
benchmarks = provider.apply(context.client());
} catch (RestClientException e) {
return;
}
String prefix = completerInvocation.getGivenCompleteValue();
if (prefix != null) {
benchmarks = benchmarks.filter(b -> b.startsWith(prefix));
}
benchmarks.forEach(completerInvocation::addCompleterValue);
}
}