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

io.hyperfoil.cli.commands.HyperfoilOptionCompleter 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.RestClientException;

public class HyperfoilOptionCompleter implements OptionCompleter {
   private final Function> provider;

   public HyperfoilOptionCompleter(Function> provider) {
      this.provider = provider;
   }

   @Override
   public void complete(HyperfoilCompleterData completerInvocation) {
      HyperfoilCliContext context = completerInvocation.getContext();
      Stream options;
      try {
         options = provider.apply(context);
      } catch (RestClientException e) {
         return;
      }
      String prefix = completerInvocation.getGivenCompleteValue();
      if (prefix != null) {
         options = options.filter(b -> b.startsWith(prefix));
      }
      options.forEach(completerInvocation::addCompleterValue);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy