mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Autocomplete export and cleanup modes
- Suggest mode and format values for datapack export - Suggest preview and apply for pack cleanup mode
This commit is contained in:
1 parent
8531fcf103
commit
cdb4e68708
7 files changed
+132
-3
No files matched your search
@@ -0,0 +1,18 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class CleanupModeHandler extends FixedChoiceHandler {
|
||||
public CleanupModeHandler() {
|
||||
super("preview", "apply");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String canonicalize(String input) {
|
||||
String mode = input.trim().toLowerCase(Locale.ROOT);
|
||||
if (!mode.equals("preview") && !mode.equals("apply")) {
|
||||
throw new IllegalArgumentException("Cleanup mode must be preview or apply.");
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.pack.datapack.export.DatapackExportDestinations;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class ExportFormatHandler extends FixedChoiceHandler {
|
||||
public ExportFormatHandler() {
|
||||
super("zip", "directory");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String canonicalize(String input) {
|
||||
return DatapackExportDestinations.parseFormat(input).name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.pack.datapack.export.WorldgenExportMode;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class ExportModeHandler extends FixedChoiceHandler {
|
||||
public ExportModeHandler() {
|
||||
super("preset", "dimension", "overworld");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String canonicalize(String input) {
|
||||
return WorldgenExportMode.parse(input).name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.command.DirectorParameterHandler;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.director.exceptions.DirectorParsingException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class FixedChoiceHandler implements DirectorParameterHandler<String> {
|
||||
private final List<String> choices;
|
||||
|
||||
protected FixedChoiceHandler(String... choices) {
|
||||
this.choices = List.of(choices);
|
||||
}
|
||||
|
||||
protected abstract String canonicalize(String input);
|
||||
|
||||
@Override
|
||||
public KList<String> getPossibilities() {
|
||||
return new KList<>(choices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(String value) {
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(String input, boolean force) throws DirectorParsingException {
|
||||
try {
|
||||
return canonicalize(input);
|
||||
} catch (IllegalArgumentException error) {
|
||||
throw new DirectorParsingException(error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> type) {
|
||||
return type == String.class;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.volmlib.util.director.exceptions.DirectorParsingException;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class FixedChoiceHandlerTest {
|
||||
@Test
|
||||
public void exportModeSuggestsAndCanonicalizesEveryMode() throws Exception {
|
||||
ExportModeHandler handler = new ExportModeHandler();
|
||||
assertEquals(List.of("preset", "dimension", "overworld"), handler.getPossibilities());
|
||||
assertEquals("preset", handler.parse(" PRESET ", false));
|
||||
assertThrows(DirectorParsingException.class, () -> handler.parse("nether", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportFormatSuggestsAndCanonicalizesAliases() throws Exception {
|
||||
ExportFormatHandler handler = new ExportFormatHandler();
|
||||
assertEquals(List.of("zip", "directory"), handler.getPossibilities());
|
||||
assertEquals("directory", handler.parse("folder", false));
|
||||
assertThrows(DirectorParsingException.class, () -> handler.parse("tar", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanupModeSuggestsAndRejectsUnknownModes() throws Exception {
|
||||
CleanupModeHandler handler = new CleanupModeHandler();
|
||||
assertEquals(List.of("preview", "apply"), handler.getPossibilities());
|
||||
assertEquals("apply", handler.parse("Apply", false));
|
||||
assertThrows(DirectorParsingException.class, () -> handler.parse("delete", false));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user