From 653e5295dedb47b06562abb799b80504bf8096e3 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sat, 12 Mar 2022 14:20:18 +0100 Subject: [PATCH] Rewrite AppOptions to instead use non-static attributes --- src/main/java/de/jotoho/waituntil/AppOptions.java | 13 +++---------- src/main/java/de/jotoho/waituntil/Main.java | 7 ++++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/jotoho/waituntil/AppOptions.java b/src/main/java/de/jotoho/waituntil/AppOptions.java index 1e1d32f..0b400a1 100644 --- a/src/main/java/de/jotoho/waituntil/AppOptions.java +++ b/src/main/java/de/jotoho/waituntil/AppOptions.java @@ -22,14 +22,7 @@ import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; final class AppOptions { - public final static Option help = Option.builder().argName("h").longOpt("help").desc("Shows this help " + "message and exits").build(); - public final static Option version = Option.builder().argName("v").longOpt("version").desc("Shows version information and exits").build(); - private final static Options options = new Options().addOption(help).addOption(version); - - // Disable Instance Creation - private AppOptions() {} - - public static Options getOptions() { - return options; - } + public final Option help = Option.builder().argName("h").longOpt("help").desc("Shows this help " + "message and exits").build(); + public final Option version = Option.builder().argName("v").longOpt("version").desc("Shows version information and exits").build(); + public final Options options = new Options().addOption(help).addOption(version); } diff --git a/src/main/java/de/jotoho/waituntil/Main.java b/src/main/java/de/jotoho/waituntil/Main.java index 1ea42c1..550f30a 100644 --- a/src/main/java/de/jotoho/waituntil/Main.java +++ b/src/main/java/de/jotoho/waituntil/Main.java @@ -55,14 +55,15 @@ public final class Main { } public static void main(final String[] args) { + final var appOptions = new AppOptions(); try { - final var parsedArguments = DefaultParser.builder().setStripLeadingAndTrailingQuotes(true).build().parse(AppOptions.getOptions(), args); + final var parsedArguments = DefaultParser.builder().setStripLeadingAndTrailingQuotes(true).build().parse(appOptions.options, args); final var userData = parsedArguments.getArgs(); - if (parsedArguments.hasOption(AppOptions.help)) { + if (parsedArguments.hasOption(appOptions.help)) { printHelpInformation(); - } else if (parsedArguments.hasOption(AppOptions.version)) { + } else if (parsedArguments.hasOption(appOptions.version)) { printVersionInformation(); } else if (userData.length == 0) { switch (applicationOutputLanguage) {