From f077a2a2596d0f6672264401ce624ebabc5882c3 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sat, 10 Jun 2023 11:10:59 -0500 Subject: [PATCH] vt: allow for newline delimited codes/files --- .../java/me/itzg/helpers/McImageHelper.java | 20 ++++--- .../itzg/helpers/sync/MulitCopyCommand.java | 5 +- .../vanillatweaks/VanillaTweaksCommand.java | 54 +++++++++++-------- 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/main/java/me/itzg/helpers/McImageHelper.java b/src/main/java/me/itzg/helpers/McImageHelper.java index 3d2f567f..13f6c4de 100644 --- a/src/main/java/me/itzg/helpers/McImageHelper.java +++ b/src/main/java/me/itzg/helpers/McImageHelper.java @@ -2,6 +2,13 @@ import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Enumeration; +import java.util.jar.Attributes; +import java.util.jar.Attributes.Name; +import java.util.jar.Manifest; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import me.itzg.helpers.assertcmd.AssertCommand; @@ -36,14 +43,6 @@ import picocli.CommandLine.IVersionProvider; import picocli.CommandLine.Option; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Enumeration; -import java.util.jar.Attributes; -import java.util.jar.Attributes.Name; -import java.util.jar.Manifest; - @Command(name = "mc-image-helper", versionProvider = McImageHelper.AppVersionProvider.class, subcommands = { @@ -74,7 +73,12 @@ @Slf4j public class McImageHelper { + //language=RegExp public static final String OPTION_SPLIT_COMMAS = "\\s*,\\s*"; + //language=RegExp + public static final String SPLIT_COMMA_NL = "[,\\n]"; + public static final String SPLIT_SYNOPSIS_COMMA_NL = ",|"; + //language=RegExp public static final String VERSION_REGEX = "\\d+(\\.\\d+)+"; @SuppressWarnings("unused") diff --git a/src/main/java/me/itzg/helpers/sync/MulitCopyCommand.java b/src/main/java/me/itzg/helpers/sync/MulitCopyCommand.java index 8a7d5d2a..f74dbfd9 100644 --- a/src/main/java/me/itzg/helpers/sync/MulitCopyCommand.java +++ b/src/main/java/me/itzg/helpers/sync/MulitCopyCommand.java @@ -1,5 +1,8 @@ package me.itzg.helpers.sync; +import static me.itzg.helpers.McImageHelper.SPLIT_COMMA_NL; +import static me.itzg.helpers.McImageHelper.SPLIT_SYNOPSIS_COMMA_NL; + import java.io.IOException; import java.net.URI; import java.nio.file.DirectoryStream; @@ -58,7 +61,7 @@ public class MulitCopyCommand implements Callable { @Option(names = "--skip-existing", defaultValue = "false") boolean skipExisting; - @Parameters(split = ",|\\n", splitSynopsisLabel = ",|", arity = "1..*", + @Parameters(split = SPLIT_COMMA_NL, splitSynopsisLabel = SPLIT_SYNOPSIS_COMMA_NL, arity = "1..*", paramLabel = "SRC", description = "Any mix of source file, directory, or URLs." + "%nCan be optionally comma or newline separated." diff --git a/src/main/java/me/itzg/helpers/vanillatweaks/VanillaTweaksCommand.java b/src/main/java/me/itzg/helpers/vanillatweaks/VanillaTweaksCommand.java index c4dfb841..2b78d30f 100644 --- a/src/main/java/me/itzg/helpers/vanillatweaks/VanillaTweaksCommand.java +++ b/src/main/java/me/itzg/helpers/vanillatweaks/VanillaTweaksCommand.java @@ -1,13 +1,39 @@ package me.itzg.helpers.vanillatweaks; +import static me.itzg.helpers.McImageHelper.SPLIT_COMMA_NL; +import static me.itzg.helpers.McImageHelper.SPLIT_SYNOPSIS_COMMA_NL; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.itzg.helpers.errors.GenericException; import me.itzg.helpers.errors.InvalidParameterException; import me.itzg.helpers.files.Manifests; -import me.itzg.helpers.http.*; +import me.itzg.helpers.http.FailedRequestException; +import me.itzg.helpers.http.Fetch; +import me.itzg.helpers.http.SharedFetch; +import me.itzg.helpers.http.SharedFetchArgs; +import me.itzg.helpers.http.Uris; import me.itzg.helpers.json.ObjectMappers; import me.itzg.helpers.singles.MoreCollections; import me.itzg.helpers.vanillatweaks.model.PackDefinition; @@ -22,24 +48,6 @@ import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.*; -import java.util.concurrent.Callable; -import java.util.stream.Collectors; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import static me.itzg.helpers.McImageHelper.OPTION_SPLIT_COMMAS; - @Command(name = "vanillatweaks", description = "Downloads Vanilla Tweaks resource packs, data packs, or crafting tweaks" + " given a share code or pack file") @Slf4j @@ -49,10 +57,14 @@ public class VanillaTweaksCommand implements Callable { public static final String MANIFEST_ID = "vanillatweaks"; private static final int FINGERPRINT_LENGTH = 7; - @Option(names = "--share-codes", required = true, split = OPTION_SPLIT_COMMAS, paramLabel = "CODE") + @Option(names = "--share-codes", split = SPLIT_COMMA_NL, splitSynopsisLabel = SPLIT_SYNOPSIS_COMMA_NL, + paramLabel = "CODE" + ) List shareCodes; - @Option(names = "--pack-files", split = OPTION_SPLIT_COMMAS, paramLabel = "FILE") + @Option(names = "--pack-files", split = SPLIT_COMMA_NL, splitSynopsisLabel = SPLIT_SYNOPSIS_COMMA_NL, + paramLabel = "FILE" + ) List packFiles; @Option(names = "--output-directory", defaultValue = ".", paramLabel = "DIR")