All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hyperfoil.cli.commands.ServerOptionCompleter Maven / Gradle / Ivy

There is a newer version: 0.27.1
Show newest version
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);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy