Skip to content

Commit

Permalink
Change to parse after last literal
Browse files Browse the repository at this point in the history
Signed-off-by: Pablete1234 <[email protected]>
  • Loading branch information
Pablete1234 committed Nov 20, 2022
1 parent aa293ce commit cdae122
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1420,14 +1420,14 @@ public enum ManagerSettings {
OVERRIDE_EXISTING_COMMANDS,

/**
* Allows parsing flags at any position by appending flag argument nodes between each command node.
* Allows parsing flags at any position after the last literal by appending flag argument nodes between each command node.
* It can have some conflicts when integrating with other command systems like Brigadier,
* and code inspecting the command tree may need to be adjusted.
*
* @since 1.8.0
*/
@API(status = API.Status.EXPERIMENTAL, since = "1.8.0")
ALLOW_FLAGS_EVERYWHERE
LIBERAL_FLAG_PARSING
}


Expand Down
10 changes: 5 additions & 5 deletions cloud-core/src/main/java/cloud/commandframework/CommandTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,11 @@ private int flagStartIndex(final List<CommandArgument<C, ?>> arguments, final Fl
return Integer.MAX_VALUE;
}

// Append flags before the first non-static argument
if (this.commandManager.getSetting(CommandManager.ManagerSettings.ALLOW_FLAGS_EVERYWHERE)) {
for (int i = 1; i < arguments.size(); i++) {
if (!(arguments.get(i) instanceof StaticArgument)) {
return i - 1;
// Append flags after the last static argument
if (this.commandManager.getSetting(CommandManager.ManagerSettings.LIBERAL_FLAG_PARSING)) {
for (int i = arguments.size() - 1; i >= 0; i--) {
if (arguments.get(i) instanceof StaticArgument) {
return i;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void testLiteralWithVariable() {
void testFlagYieldingGreedyStringFollowedByFlagArgument() {
// Arrange
final CommandManager<TestCommandSender> manager = createManager();
manager.setSetting(CommandManager.ManagerSettings.ALLOW_FLAGS_EVERYWHERE, true);
manager.setSetting(CommandManager.ManagerSettings.LIBERAL_FLAG_PARSING, true);
manager.command(
manager.commandBuilder("command")
.argument(
Expand Down Expand Up @@ -454,7 +454,7 @@ void testFlagYieldingGreedyStringFollowedByFlagArgument() {
void testFlagYieldingStringArrayFollowedByFlagArgument() {
// Arrange
final CommandManager<TestCommandSender> manager = createManager();
manager.setSetting(CommandManager.ManagerSettings.ALLOW_FLAGS_EVERYWHERE, true);
manager.setSetting(CommandManager.ManagerSettings.LIBERAL_FLAG_PARSING, true);
manager.command(
manager.commandBuilder("command")
.argument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ArbitraryPositionFlagTest {
@BeforeEach
void setup() {
this.commandManager = createManager();
this.commandManager.setSetting(CommandManager.ManagerSettings.ALLOW_FLAGS_EVERYWHERE, true);
this.commandManager.setSetting(CommandManager.ManagerSettings.LIBERAL_FLAG_PARSING, true);

this.commandManager.command(
this.commandManager.commandBuilder("test")
Expand Down

0 comments on commit cdae122

Please sign in to comment.