diff --git a/ModsListDownloader/src/downloader/Main.java b/ModsListDownloader/src/downloader/Main.java index 95341d2..f0ae96b 100644 --- a/ModsListDownloader/src/downloader/Main.java +++ b/ModsListDownloader/src/downloader/Main.java @@ -14,8 +14,15 @@ public class Main { public static String mcVersion; public static void main(String[] args) { - mcVersion = "1.12.2"; - + if(mcVersion == null) { + mcVersion = "1.12.2"; + } + else { + if(!isVersionValid()) { + Log.e("main", "the version number provided is invalid"); + System.exit(1); + } + } checkModsDirectory(); new DatabaseVersionManager().updateIfNeeded(); interpretArgs(args); @@ -64,16 +71,18 @@ public class Main { case "-v": verbose = true; break; + + case "-version": + checkNext(it); + mcVersion = it.next(); + break; case "--thread": if (threadNb != null) { Log.e("main", "error conflicting arguments --thread and -t"); System.exit(1); } - if (!it.hasNext()) { - Log.e("main", "arguments invalid please refer to --help"); - System.exit(1); - } + checkNext(it); String threadNumber = it.next(); if (threadNumber.matches("[0-9]*")) { threadNb = Integer.valueOf(Integer.parseInt(threadNumber)); @@ -93,4 +102,22 @@ public class Main { } } } + + private static boolean isVersionValid() { + switch(mcVersion.split(".").length) { + case 2: + return mcVersion.matches("[0-9]*\\.[0-9]*"); + case 3: + return mcVersion.matches("[0-9]*\\.[0-9]*\\.[0-9]*"); + default: + return false; + } + } + + private static void checkNext(Iterator it) { + if (!it.hasNext()) { + Log.e("main", "arguments invalid please refer to --help"); + System.exit(1); + } + } }