Skip to content

Commit 97121ac

Browse files
committed
Refine command programming model
- Introduce command exit status and exception mapper - Add support for arguments and options - Remove AST-based command parsing and make the parser swappable - Simplify command alias type - Handle command help requests in AbstractCommand - Add command utilities Sub commands and aliases are not implemented yet.
1 parent 7199ea4 commit 97121ac

File tree

79 files changed

+727
-5414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+727
-5414
lines changed

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

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

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

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

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ default String getDescription() {
4848
* @return the help text of the command
4949
*/
5050
default String getHelp() {
51-
// TODO generate default help from description, options, aliases, etc.
52-
return "";
51+
return getName() + "(" + String.join(",", getAliases()) + "): " + getDescription();
5352
}
5453

5554
/**
@@ -60,26 +59,19 @@ default String getGroup() {
6059
return "";
6160
}
6261

63-
/**
64-
* Get the options of the command.
65-
* @return the options of the command
66-
*/
67-
default List<CommandOption> getOptions() {
68-
return Collections.emptyList();
69-
}
70-
7162
/**
7263
* Get the aliases of the command.
7364
* @return the aliases of the command
7465
*/
75-
default List<CommandAlias> getAliases() {
66+
default List<String> getAliases() {
7667
return Collections.emptyList();
7768
}
7869

7970
/**
8071
* Execute the command within the given context.
8172
* @param commandContext the context of the command
73+
* @return the exit status of the command
8274
*/
83-
void execute(CommandContext commandContext) throws Exception;
75+
ExitStatus execute(CommandContext commandContext) throws Exception;
8476

8577
}

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

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 the original author or authors.
2+
* Copyright 2025-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,10 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.shell.core.command.parser;
16+
package org.springframework.shell.core.command;
1717

18-
public enum TokenType {
19-
20-
ARGUMENT, COMMAND, OPTION, DOUBLEDASH, DIRECTIVE
18+
/**
19+
* Record representing a runtime argument to a command.
20+
*
21+
* @author Mahmoud Ben Hassine
22+
* @since 4.0.0
23+
*/
24+
public record CommandArgument(int index, String value) {
2125

2226
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 the original author or authors.
2+
* Copyright 2022-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,12 +20,13 @@
2020
import org.jline.terminal.Terminal;
2121

2222
/**
23-
* Interface containing information about current command execution.
23+
* Interface containing information about the current command invocation.
2424
*
2525
* @author Janne Valkealahti
2626
* @author Piotr Olaszewski
2727
* @author Mahmoud Ben Hassine
2828
*/
29-
public record CommandContext(List<String> rawArgs, CommandRegistry commandRegistry, Terminal terminal) {
29+
public record CommandContext(List<CommandOption> options, List<CommandArgument> arguments,
30+
CommandRegistry commandRegistry, Terminal terminal) {
3031

3132
}

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

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

0 commit comments

Comments
 (0)