Skip to content

Commit baee81c

Browse files
committed
Refactor
Signed-off-by: Piotr Olaszewski <[email protected]>
1 parent 9644561 commit baee81c

25 files changed

+317
-454
lines changed

spring-shell-core/src/main/java/org/springframework/shell/core/Shell.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import org.springframework.shell.core.command.CommandRegistry;
4343
import org.springframework.shell.core.command.CommandExecution.CommandExecutionException;
4444
import org.springframework.shell.core.command.CommandExecution.CommandExecutionHandlerMethodArgumentResolvers;
45+
import org.springframework.shell.core.command.metadata.CommandAlias;
46+
import org.springframework.shell.core.command.metadata.CommandHandlingResult;
4547
import org.springframework.shell.core.command.metadata.CommandOption;
4648
import org.springframework.shell.core.completion.CompletionContext;
4749
import org.springframework.shell.core.completion.CompletionProposal;
@@ -230,7 +232,7 @@ else if (processExceptionNonInt != null && processExceptionNonInt.exitCode() !=
230232
return true;
231233
}
232234
for (CommandAlias a : r.getAliases()) {
233-
if (a.getCommand().equals(command)) {
235+
if (a.command().equals(command)) {
234236
return true;
235237
}
236238
}
@@ -244,7 +246,7 @@ else if (processExceptionNonInt != null && processExceptionNonInt.exitCode() !=
244246
if (this.exitCodeMappings != null) {
245247
List<Function<Throwable, Integer>> mappingFunctions = commandRegistration.get()
246248
.getExitCode()
247-
.getMappingFunctions();
249+
.mappingFunctions();
248250
this.exitCodeMappings.reset(mappingFunctions);
249251
}
250252

spring-shell-core/src/main/java/org/springframework/shell/core/command/Command.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626

2727
import org.springframework.core.ResolvableType;
2828
import org.springframework.shell.core.command.availability.Availability;
29+
import org.springframework.shell.core.command.metadata.CommandAlias;
30+
import org.springframework.shell.core.command.metadata.CommandExitCode;
2931
import org.springframework.shell.core.command.metadata.CommandOption;
3032
import org.springframework.shell.core.command.metadata.CommandTarget;
33+
import org.springframework.shell.core.command.metadata.CommandHelpOptionInfo;
3134
import org.springframework.shell.core.completion.CompletionResolver;
3235
import org.springframework.shell.core.context.InteractionMode;
3336

@@ -111,7 +114,7 @@ public interface Command {
111114
* Returns the help option info.
112115
* @return the help option info
113116
*/
114-
HelpOptionInfo getHelpOption();
117+
CommandHelpOptionInfo getHelpOption();
115118

116119
/**
117120
* Creates a new {@link Builder} instance.

spring-shell-core/src/main/java/org/springframework/shell/core/command/CommandAlias.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

spring-shell-core/src/main/java/org/springframework/shell/core/command/CommandExceptionResolver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.jspecify.annotations.Nullable;
1919
import org.springframework.core.Ordered;
2020
import org.springframework.core.annotation.Order;
21+
import org.springframework.shell.core.command.metadata.CommandHandlingResult;
2122

2223
/**
2324
* Interface to be implemented by objects that can resolve exceptions thrown during

spring-shell-core/src/main/java/org/springframework/shell/core/command/CommandExecution.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.springframework.shell.core.command.metadata.CommandTarget.TargetType;
4242
import org.springframework.shell.core.command.invocation.InvocableShellMethod;
4343
import org.springframework.shell.core.command.invocation.ShellMethodArgumentResolverComposite;
44+
import org.springframework.shell.core.command.metadata.CommandHelpOptionInfo;
4445
import org.springframework.shell.core.command.parser.ParserConfig;
4546
import org.springframework.shell.core.context.ShellContext;
4647
import org.springframework.util.Assert;
@@ -143,26 +144,25 @@ public DefaultCommandExecution(@Nullable List<? extends HandlerMethodArgumentRes
143144

144145
// check help options to short circuit
145146
boolean handleHelpOption = false;
146-
HelpOptionInfo helpOption = registration.getHelpOption();
147-
if (helpOption.isEnabled() && helpOption.getCommand() != null
148-
&& (!ObjectUtils.isEmpty(helpOption.getLongNames())
149-
|| !ObjectUtils.isEmpty(helpOption.getShortNames()))) {
147+
CommandHelpOptionInfo helpOption = registration.getHelpOption();
148+
if (helpOption.enabled() && helpOption.command() != null && (!ObjectUtils.isEmpty(helpOption.longNames())
149+
|| !ObjectUtils.isEmpty(helpOption.shortNames()))) {
150150
handleHelpOption = results.results().stream().filter(cpr -> {
151151
boolean present = false;
152-
if (helpOption.getLongNames() != null) {
152+
if (helpOption.longNames() != null) {
153153
present = Arrays.asList(cpr.option().longNames())
154154
.stream()
155-
.filter(ln -> ObjectUtils.containsElement(helpOption.getLongNames(), ln))
155+
.filter(ln -> ObjectUtils.containsElement(helpOption.longNames(), ln))
156156
.findFirst()
157157
.isPresent();
158158
}
159159
if (present) {
160160
return true;
161161
}
162-
if (helpOption.getShortNames() != null) {
162+
if (helpOption.shortNames() != null) {
163163
present = Arrays.asList(cpr.option().shortNames())
164164
.stream()
165-
.filter(sn -> ObjectUtils.containsElement(helpOption.getShortNames(), sn))
165+
.filter(sn -> ObjectUtils.containsElement(helpOption.shortNames(), sn))
166166
.findFirst()
167167
.isPresent();
168168
}
@@ -175,7 +175,7 @@ public DefaultCommandExecution(@Nullable List<? extends HandlerMethodArgumentRes
175175
if (handleHelpOption) {
176176
String command = registration.getCommand();
177177
CommandParser helpParser = CommandParser.of(conversionService, registrations, new ParserConfig());
178-
Command helpCommand = registrations.get(registration.getHelpOption().getCommand());
178+
Command helpCommand = registrations.get(registration.getHelpOption().command());
179179
CommandParserResults helpResults = helpParser.parse(new String[] { "help", "--command", command });
180180
results = helpResults;
181181
usedRegistration = helpCommand;

spring-shell-core/src/main/java/org/springframework/shell/core/command/CommandExitCode.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

spring-shell-core/src/main/java/org/springframework/shell/core/command/CommandHandlingResult.java

Lines changed: 0 additions & 117 deletions
This file was deleted.

spring-shell-core/src/main/java/org/springframework/shell/core/command/CommandParserExceptionResolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
import org.jline.utils.AttributedString;
1919
import org.jline.utils.AttributedStringBuilder;
2020
import org.jline.utils.AttributedStyle;
21-
2221
import org.jspecify.annotations.Nullable;
22+
2323
import org.springframework.shell.core.command.CommandExecution.CommandParserExceptionsException;
24+
import org.springframework.shell.core.command.metadata.CommandHandlingResult;
2425

2526
/**
2627
* Handles {@link CommandParserExceptionsException}.
@@ -40,7 +41,7 @@ public class CommandParserExceptionResolver implements CommandExceptionResolver
4041
builder.append("\n");
4142
});
4243
String as = builder.toAttributedString().toAnsi();
43-
return CommandHandlingResult.of(as);
44+
return new CommandHandlingResult(as);
4445
}
4546
return null;
4647
}

0 commit comments

Comments
 (0)