Compare commits
No commits in common. "3c40095b1dfc6dc2a3a2e21a3fb1dd6fcb9c4d1c" and "ae110424421281f9ff0642a6d67514ae11302768" have entirely different histories.
3c40095b1d
...
ae11042442
4 changed files with 49 additions and 88 deletions
|
@ -12,10 +12,6 @@ repositories {
|
|||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(group="commons-cli", name="commons-cli", version="1.5.0")
|
||||
}
|
||||
|
||||
fun versionBanner(): String {
|
||||
val os = ByteArrayOutputStream()
|
||||
val devNull = OutputStream.nullOutputStream()
|
||||
|
@ -40,8 +36,8 @@ tasks.jar {
|
|||
attributes(
|
||||
"Implementation-Title" to project.name,
|
||||
"Implementation-Version" to project.version,
|
||||
"Main-Class" to "de.jotoho.waituntil.Main"
|
||||
//"Main-Module" to "de.jotoho.waituntil.main"
|
||||
"Main-Class" to "de.jotoho.waituntil.Main",
|
||||
"Main-Module" to "de.jotoho.waituntil.main"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -49,5 +45,5 @@ tasks.jar {
|
|||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass.set("de.jotoho.waituntil.Main")
|
||||
//mainModule.set("de.jotoho.waituntil.main")
|
||||
mainModule.set("de.jotoho.waituntil.main")
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package de.jotoho.waituntil;
|
||||
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
|
||||
final class AppOptions {
|
||||
// Disable Instance Creation
|
||||
private 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);
|
||||
|
||||
public static Options getOptions() {
|
||||
return options;
|
||||
}
|
||||
}
|
|
@ -18,8 +18,8 @@ package de.jotoho.waituntil;
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.jotoho.waituntil.GlobalConf.applicationOutputLanguage;
|
||||
|
||||
|
@ -28,67 +28,53 @@ import static de.jotoho.waituntil.GlobalConf.applicationOutputLanguage;
|
|||
// Author: Jonas Tobias Hopusch (@jotoho)
|
||||
|
||||
public final class Main {
|
||||
|
||||
private static void printVersionInformation() {
|
||||
final var thisPackage = Main.class.getPackage();
|
||||
final var appVersion = thisPackage.getImplementationVersion() != null ? thisPackage.getImplementationVersion() : "version unknown";
|
||||
System.out.println("waituntil " + appVersion);
|
||||
System.out.println("""
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the
|
||||
GNU General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU General Public License for more details.""");
|
||||
}
|
||||
|
||||
private static void printHelpInformation() {
|
||||
switch (applicationOutputLanguage) {
|
||||
case GlobalConf.langGerman -> System.out.println("Hilfe kommt noch. (Nicht implementiert)");
|
||||
default -> System.out.println("Help is yet to come. (Not implemented)");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(final String[] args) {
|
||||
try {
|
||||
final var parsedArguments =
|
||||
DefaultParser.builder()
|
||||
.setStripLeadingAndTrailingQuotes(true)
|
||||
.build()
|
||||
.parse(AppOptions.getOptions(), args);
|
||||
final var optionDictionary = Map.of("-h", "--help", "-v", "--version");
|
||||
|
||||
final var userData = parsedArguments.getArgs();
|
||||
final var options = new HashSet<String>();
|
||||
final var words = new HashSet<String>();
|
||||
|
||||
if (parsedArguments.hasOption(AppOptions.help)) {
|
||||
printHelpInformation();
|
||||
} else if (parsedArguments.hasOption(AppOptions.version)) {
|
||||
printVersionInformation();
|
||||
} else if (userData.length == 0) {
|
||||
switch (applicationOutputLanguage) {
|
||||
case GlobalConf.langGerman -> System.err.println("FATAL: " +
|
||||
"Es wurde keine Uhrzeit angegeben.");
|
||||
default -> System.err.println("FATAL: No target time was " +
|
||||
"provided.");
|
||||
}
|
||||
System.exit(1);
|
||||
} else if (userData.length > 1) {
|
||||
switch (applicationOutputLanguage) {
|
||||
case GlobalConf.langGerman -> System.err.println("FATAL: " +
|
||||
"Zu viele Argumente wurden angegeben.");
|
||||
default -> System.err.println("FATAL: Too many arguments " +
|
||||
"provided.");
|
||||
}
|
||||
System.exit(1);
|
||||
for (final String arg : args) {
|
||||
if (arg.startsWith("--")) {
|
||||
options.add(arg.substring(2));
|
||||
} else if (arg.startsWith("-")) {
|
||||
if (optionDictionary.containsKey(arg))
|
||||
options.add(optionDictionary.get(arg).substring(2));
|
||||
else
|
||||
System.err.println("Short-hand '$arg' does not exist. Ignoring!");
|
||||
} else {
|
||||
final var target =
|
||||
TimeCalculator.calculateAndAnnounceTargetTime(userData[0]);
|
||||
Sleep.waitUntilTimeStamp(target);
|
||||
words.add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.contains("help")) {
|
||||
switch (applicationOutputLanguage) {
|
||||
case GlobalConf.langGerman -> System.out.println("Hilfe kommt noch. (Nicht implementiert)");
|
||||
default -> System.out.println("Help is yet to come. (Not implemented)");
|
||||
}
|
||||
} else if (options.contains("version")) {
|
||||
final var thisPackage = Main.class.getPackage();
|
||||
final var appVersion = thisPackage.getImplementationVersion() != null
|
||||
? thisPackage.getImplementationVersion()
|
||||
: "version unknown";
|
||||
System.out.println("waituntil " + appVersion);
|
||||
System.out.println("""
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the
|
||||
GNU General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU General Public License for more details.""");
|
||||
} else if (words.size() == 1) {
|
||||
final var target = TimeCalculator.calculateAndAnnounceTargetTime(words.iterator().next());
|
||||
Sleep.waitUntilTimeStamp(target);
|
||||
} else {
|
||||
switch (applicationOutputLanguage) {
|
||||
case GlobalConf.langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (" + words.size() + " erhalten)");
|
||||
default -> System.err.println("FATAL: Expected one non-flag argument. (Got " + words.size() + ")");
|
||||
}
|
||||
} catch (final ParseException e) {
|
||||
System.getLogger("main").log(System.Logger.Level.ERROR, "Parsing " +
|
||||
"of arguments failed and the program cannot continue.", e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
|
2
src/main/java/module-info.java
Normal file
2
src/main/java/module-info.java
Normal file
|
@ -0,0 +1,2 @@
|
|||
module de.jotoho.waituntil.main {
|
||||
}
|
Loading…
Reference in a new issue