Skip to content

Commit

Permalink
feat: update to ExecutionCoordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
Citymonstret committed Jan 1, 2024
1 parent 4b002c3 commit 8e3b582
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 59 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@

import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.suggestion.SuggestionFactory;
import cloud.commandframework.arguments.suggestion.Suggestions;
import cloud.commandframework.context.CommandInput;
import cloud.commandframework.exceptions.ArgumentParseException;
import cloud.commandframework.exceptions.InvalidCommandSenderException;
import cloud.commandframework.exceptions.InvalidSyntaxException;
import cloud.commandframework.exceptions.NoPermissionException;
import cloud.commandframework.exceptions.NoSuchCommandException;
import cloud.commandframework.execution.FilteringCommandSuggestionProcessor;
import cloud.commandframework.execution.ExecutionCoordinator;
import cloud.commandframework.keys.CloudKey;
import cloud.commandframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -70,27 +72,24 @@ public class SpringCommandManager<C> extends CommandManager<C> implements Comple
/**
* Creates a new command manager.
*
* @param commandExecutionCoordinatorResolver the resolver for the execution coordinator
* @param executionCoordinator the execution coordinator
* @param commandPermissionHandler the permission handler
* @param commandRegistrationHandler the registration handler
* @param commandSenderMapper the mapper for the custom command sender type
* @param applicationContext the application context
*/
public SpringCommandManager(
final @NonNull SpringCommandExecutionCoordinatorResolver<C> commandExecutionCoordinatorResolver,
final @NonNull ExecutionCoordinator<C> executionCoordinator,
final @NonNull SpringCommandPermissionHandler<C> commandPermissionHandler,
final @NonNull SpringCommandRegistrationHandler<C> commandRegistrationHandler,
final @NonNull CommandSenderMapper<C> commandSenderMapper,
final @NonNull ApplicationContext applicationContext
) {
super(commandExecutionCoordinatorResolver, commandRegistrationHandler);
super(executionCoordinator, commandRegistrationHandler);
this.commandPermissionHandler = commandPermissionHandler;
this.commandSenderMapper = commandSenderMapper;
this.suggestionFactory = super.suggestionFactory().mapped(CloudCompletionProposal::fromSuggestion);
this.parameterInjectorRegistry().registerInjectionService(new SpringInjectionService<>(applicationContext));
this.commandSuggestionProcessor(new FilteringCommandSuggestionProcessor<>(
FilteringCommandSuggestionProcessor.Filter.<C>startsWith(true).andTrimBeforeLastSpace()
));

this.registerDefaultExceptionHandlers();
}
Expand Down Expand Up @@ -125,7 +124,12 @@ void commandExecutionEvent(final @NonNull CommandExecutionEvent<C> event) {
strings.addAll(completionContext.getWords());
final String input = String.join(" ", strings);

return this.suggestionFactory().suggestImmediately(this.commandSenderMapper.map(null), input).stream()
final Suggestions<C, ? extends CompletionProposal> suggestions =
this.suggestionFactory.suggestImmediately(this.commandSenderMapper.map(null), input);
return suggestions.list()
.stream()
.map(suggestion -> suggestion.withSuggestion(StringUtils.trimBeforeLastSpace(suggestion.suggestion(),
suggestions.commandInput())))
.map(suggestion -> (CompletionProposal) suggestion)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
//
package org.incendo.cloud.spring.config;

import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.execution.ExecutionCoordinator;
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.spring.CommandSenderMapper;
import org.incendo.cloud.spring.SpringCommandExecutionCoordinatorResolver;
import org.incendo.cloud.spring.SpringCommandPermissionHandler;
import org.incendo.cloud.spring.SpringCommandSender;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -50,9 +49,9 @@ public class CloudSpringConfig {
}

@Bean
@ConditionalOnMissingBean(SpringCommandExecutionCoordinatorResolver.class)
@NonNull SpringCommandExecutionCoordinatorResolver<?> commandExecutionCoordinatorResolver() {
return CommandExecutionCoordinator.simpleCoordinator()::apply;
@ConditionalOnMissingBean(ExecutionCoordinator.class)
@NonNull ExecutionCoordinator<?> executionCoordinator() {
return ExecutionCoordinator.simpleCoordinator();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import cloud.commandframework.CommandProperties;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.context.StandardCommandContextFactory;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.execution.ExecutionCoordinator;
import cloud.commandframework.internal.CommandNode;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -61,13 +61,6 @@ void test() {
assertThat(this.springCommandManager).isNotNull();
}

@Test
@DisplayName("Verify that the command execution coordinator was overridden")
void testCommandExecutionCoordinator() {
assertThat(this.springCommandManager.commandExecutor().commandExecutionCoordinator())
.isInstanceOf(AsynchronousCommandExecutionCoordinator.class);
}

@Test
@DisplayName("Verify that the command bean was registered")
void testCommandRegistration() {
Expand Down Expand Up @@ -108,8 +101,8 @@ static class TestConfig {
}

@Bean
@NonNull SpringCommandExecutionCoordinatorResolver<TestCommandSender> commandExecutionCoordinatorResolver() {
return AsynchronousCommandExecutionCoordinator.<TestCommandSender>builder().withAsynchronousParsing().build()::apply;
@NonNull ExecutionCoordinator<TestCommandSender> executionCoordinator() {
return ExecutionCoordinator.asyncCoordinator();
}

@Bean
Expand Down

0 comments on commit 8e3b582

Please sign in to comment.