Class CommandProvider


  • public final class CommandProvider
    extends Object
    Provides a set of commands. Each command handler provides their own way to handle errors via a CommandErrorHandler.
    • Constructor Detail

      • CommandProvider

        public CommandProvider​(String name)
    • Method Detail

      • getName

        public String getName()
        Gets the name of this command provider.
        Returns:
        the name of this command provider
      • add

        public void add​(Command command)
        Adds a command to this provider.
        Parameters:
        command - the command to add
      • addAnnotated

        public void addAnnotated​(Object annotated)
        Adds an annotated object as a command into this provider. This is equivalent to doing:
         provider.add(AnnotatedCommand.from(object, provider));
         
        Parameters:
        annotated - the annotated object to add
      • addAllFromModule

        public reactor.core.publisher.Flux<Object> addAllFromModule​(Module module)
        Scans the module path and adds all commands that are found in the given module. The command's class needs to be annotated with CommandDescriptor and have a no-arg constructor.

        Since module path scanning requires I/O operations, this method returns a Flux that subscribes on Schedulers.boundedElastic().

        This method is equivalent to addAllFromModule(module, null)

        Parameters:
        module - the Java module where to find the commands
        Returns:
        a Flux emitting the instances of the annotated command classes, created by the module path scanning process. If an error happened during the scan, the Flux will error.
      • addAllFromModule

        public reactor.core.publisher.Flux<Object> addAllFromModule​(Module module,
                                                                    @Nullable
                                                                    Predicate<String> classNameFilter)
        Scans the module path and adds all commands that are found in the given module. The command's class needs to be annotated with CommandDescriptor and have a no-arg constructor.

        Since module path scanning requires I/O operations, this method returns a Flux that subscribes on Schedulers.boundedElastic().

        Parameters:
        module - the Java module where to find the commands
        classNameFilter - a filter to include only certain classes, null to accept all classes
        Returns:
        a Flux emitting the instances of the annotated command classes, created by the module path scanning process. If an error happened during the scan, the Flux will error.
      • getCommandByAlias

        public Optional<Command> getCommandByAlias​(String alias)
        Gets a command instance corresponding to the given alias.
        Parameters:
        alias - the alias of the command
        Returns:
        the corresponding command instance, if present
      • getErrorHandler

        public CommandErrorHandler getErrorHandler()
        Gets the error handler assigned to this provider.
        Returns:
        the error handler
      • setErrorHandler

        public void setErrorHandler​(CommandErrorHandler errorHandler)
        Sets a custom command handler. If this method is not called, a default handler will be used.
        Parameters:
        errorHandler - the error handler to set
      • getPermissionChecker

        public PermissionChecker getPermissionChecker()
        Gets the permission checker assigned to this provider.
        Returns:
        the permission checker
      • setPermissionChecker

        public void setPermissionChecker​(PermissionChecker permissionChecker)
        Sets a custom permission checker. If this method is not called, an empty permission checker will be used.
        Parameters:
        permissionChecker - the permission checker to set
      • getProvidedCommands

        public Set<Command> getProvidedCommands()
        Gets all provided commands.
        Returns:
        an unmodifiable Set containing all commands provided by this provider
      • addParamConverter

        public void addParamConverter​(ParamConverter<?> converter)
        Adds a new param converter to this annotated command provider.
        Parameters:
        converter - the converter to add
      • convertParam

        public <T> reactor.core.publisher.Mono<T> convertParam​(Context ctx,
                                                               String input,
                                                               Class<T> targetType)