From 3e74e2351285a7b9a3384d1207e28b180b03f52d Mon Sep 17 00:00:00 2001 From: RatzzFatzz Date: Thu, 18 Dec 2025 21:17:51 +0100 Subject: [PATCH] Remove attribute config as required option --- .../impl/CommandRunner.java | 16 +++++-------- .../impl/processors/AttributeUpdater.java | 2 +- .../model/InputConfig.java | 11 +++++---- .../CoherentAttributeUpdaterTest.java | 5 ++-- .../ValidationExecutionStrategyTest.java | 23 +++++++++---------- .../util/TestUtil.java | 6 ++--- 6 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/CommandRunner.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/CommandRunner.java index 7d48c0d..e1c4bd9 100644 --- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/CommandRunner.java +++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/CommandRunner.java @@ -1,11 +1,6 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl; -import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.AttributeUpdater; -import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.CoherentAttributeUpdater; -import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.SingleFileAttributeUpdater; -import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.CachedFileProcessor; -import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.FileProcessor; -import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.MkvFileProcessor; +import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.*; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig; import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil; import lombok.Getter; @@ -19,8 +14,8 @@ import picocli.CommandLine; name = "mkvaudiosubtitlechanger", usageHelpAutoWidth = true, customSynopsis = { - "mkvaudiosubtitlechanger -a [...] -l [-s]", - "Example: mkvaudiosubtitlechanger -a eng:eng eng:ger -l /mnt/media/ -s", + "mkvaudiosubtitlechanger [-a [...]] [-s] ", + "Example: mkvaudiosubtitlechanger -a eng:eng eng:ger -s /mnt/media/", "" }, requiredOptionMarker = '*', @@ -41,10 +36,11 @@ public class CommandRunner implements Runnable { FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate()); FileProcessor fileProcessor = new CachedFileProcessor(new MkvFileProcessor(config.getMkvToolNix(), fileFilter)); + AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired()); AttributeUpdater kernel = config.getCoherent() != null - ? new CoherentAttributeUpdater(config, fileProcessor) - : new SingleFileAttributeUpdater(config, fileProcessor); + ? new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor) + : new SingleFileAttributeUpdater(config, fileProcessor, attributeChangeProcessor); kernel.execute(); } } diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdater.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdater.java index d49f385..56ad594 100644 --- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdater.java +++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdater.java @@ -27,7 +27,7 @@ public abstract class AttributeUpdater { private final ExecutorService executor; - public AttributeUpdater(InputConfig config, FileProcessor fileProcessor) { + public AttributeUpdater(InputConfig config, FileProcessor fileProcessor, AttributeChangeProcessor attributeChangeProcessor) { this.config = config; this.fileProcessor = fileProcessor; this.attributeChangeProcessor = attributeChangeProcessor; diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/InputConfig.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/InputConfig.java index 44dd923..ef848dd 100644 --- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/InputConfig.java +++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/InputConfig.java @@ -28,12 +28,13 @@ public class InputConfig implements CommandLine.IVersionProvider { @CommandLine.Spec CommandLine.Model.CommandSpec spec; - @Option(names = {"-a", "--attribute-config"}, required = true, arity = "1..*", converter = AttributeConfigConverter.class, - description = "List of audio:subtitle pairs used to match in order and update files accordingly (e.g. jpn:eng jpn:ger)") - private AttributeConfig[] attributeConfig; @ValidFile(message = "does not exist") - @Option(names = {"-l", "--library"}, required = true, description = "path to library") + @CommandLine.Parameters(description = "path to library") private File libraryPath; + + @Option(names = {"-a", "--attribute-config"}, arity = "1..*", converter = AttributeConfigConverter.class, + description = "List of audio:subtitle pairs used to match in order and update files accordingly (e.g. jpn:eng jpn:ger)") + private AttributeConfig[] attributeConfig = new AttributeConfig[0]; @ValidMkvToolNix(message = "does not exist") @Option(names = {"-m", "--mkvtoolnix"}, defaultValue = "${DEFAULT_MKV_TOOL_NIX}", description = "path to mkvtoolnix installation") private File mkvToolNix; @@ -90,8 +91,8 @@ public class InputConfig implements CommandLine.IVersionProvider { return new StringJoiner(", ", InputConfig.class.getSimpleName() + "[", "]") .add("configPath=" + configPath) .add("spec=" + spec) - .add("attributeConfig=" + Arrays.toString(attributeConfig)) .add("libraryPath=" + libraryPath) + .add("attributeConfig=" + Arrays.toString(attributeConfig)) .add("mkvToolNix=" + mkvToolNix) .add("safeMode=" + safeMode) .add("threads=" + threads) diff --git a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdaterTest.java b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdaterTest.java index b851085..afc05e8 100644 --- a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdaterTest.java +++ b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdaterTest.java @@ -65,9 +65,10 @@ class CoherentAttributeUpdaterTest { @MethodSource("findMatch") void findMatch(AttributeConfig attributeConfig, List> fileInfoMock, boolean expectedMatch, int expectedMatchCount) throws InvocationTargetException, IllegalAccessException { CommandRunner commandRunner = new CommandRunner(); - new CommandLine(commandRunner).parseArgs("-l", "/arst", "-a", "ger:ger"); + new CommandLine(commandRunner).parseArgs("-a", "ger:ger", "/arst"); InputConfig config = commandRunner.getConfig(); - CoherentAttributeUpdater updater = new CoherentAttributeUpdater(config, fileProcessor, null); + AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired()); + CoherentAttributeUpdater updater = new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor); Set matchedFiles = new HashSet<>(fileInfoMock.size() * 2); List files = new ArrayList<>(); diff --git a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/validation/ValidationExecutionStrategyTest.java b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/validation/ValidationExecutionStrategyTest.java index 571b3d4..41a5d04 100644 --- a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/validation/ValidationExecutionStrategyTest.java +++ b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/validation/ValidationExecutionStrategyTest.java @@ -22,7 +22,7 @@ class ValidationExecutionStrategyTest { CommandRunner underTest = new CommandRunner(); new CommandLine(underTest) .setExecutionStrategy(new ValidationExecutionStrategy()) - .parseArgs("-a", "ger:ger", "-l", TEST_FILE, "-m", TEST_MKVTOOLNIX_DIR); + .parseArgs("-a", "ger:ger", "-m", TEST_MKVTOOLNIX_DIR, TEST_FILE); assertEquals(TEST_FILE, underTest.getConfig().getLibraryPath().getPath().replace("\\", "/")); assertEquals(TEST_MKVTOOLNIX_DIR, underTest.getConfig().getMkvToolNix().getPath().replace("\\", "/")); @@ -30,17 +30,16 @@ class ValidationExecutionStrategyTest { private static Stream validateFailure() { return Stream.of( - Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): --library="), - Arguments.of(new String[]{"-a", "jpn:ger", "-l"}, "Missing required parameter for option '--library' ()"), - Arguments.of(new String[]{"-l", "/arstarstarst"}, "Error: Missing required argument(s): --attribute-config="), - Arguments.of(new String[]{"-l", "/arstarstarst", "-a",}, "Missing required parameter for option '--attribute-config' at index 0 ()"), - Arguments.of(new String[]{"-l", "/arstarstarst", "-a", "jpn:ger"}, "libraryPath does not exist"), - Arguments.of(args("-m"), "Missing required parameter for option '--mkvtoolnix' ()"), - Arguments.of(args("-m", TEST_INVALID_DIR), "mkvToolNix does not exist"), - Arguments.of(args("-t"), "Missing required parameter for option '--threads' ()"), - Arguments.of(args("-t", "0"), "threads must be greater than or equal to 1"), - Arguments.of(args("-t", "-1"), "threads must be greater than or equal to 1"), - Arguments.of(args("-c", "-1"), "coherent must be greater than or equal to 0") + Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): "), + Arguments.of(new String[]{"/arstarstarst"}, "libraryPath does not exist"), + Arguments.of(new String[]{"/arstarstarst", "-a",}, "Missing required parameter for option '--attribute-config' at index 0 ()"), + Arguments.of(new String[]{"/arstarstarst", "-a", "jpn:ger"}, "libraryPath does not exist"), + Arguments.of(new String[]{"/arstarstarst", "-m"}, "Missing required parameter for option '--mkvtoolnix' ()"), + Arguments.of(new String[]{"./", "-m", TEST_INVALID_DIR}, "mkvToolNix does not exist"), + Arguments.of(new String[]{"./", "-t"}, "Missing required parameter for option '--threads' ()"), + Arguments.of(new String[]{"./", "-t", "0"}, "threads must be greater than or equal to 1"), + Arguments.of(new String[]{"./", "-t", "-1"}, "threads must be greater than or equal to 1"), + Arguments.of(new String[]{"./", "-c", "-1"}, "coherent must be greater than or equal to 0") ); } diff --git a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/util/TestUtil.java b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/util/TestUtil.java index f0c665c..0135dce 100644 --- a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/util/TestUtil.java +++ b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/util/TestUtil.java @@ -3,10 +3,10 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.util; public class TestUtil { public static String[] args(String... args) { - String[] staticArray = new String[]{"-l", "/", "-a", "jpn:ger"}; + String[] staticArray = new String[]{"-a", "jpn:ger", "/"}; String[] result = new String[staticArray.length + args.length]; - System.arraycopy(staticArray, 0, result, 0, staticArray.length); - System.arraycopy(args, 0, result, staticArray.length, args.length); + System.arraycopy(args, 0, result, 0, args.length); + System.arraycopy(staticArray, 0, result, args.length, staticArray.length); return result; } }