From 09cf7a916817fd23ccf028b8855af7eab0965939 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 22:12:03 +0200 Subject: [PATCH] Go back to unclassed functions and use DummyClass instead --- .../jotoho/waituntil/{start.kt => Start.kt} | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) rename src/main/kotlin/de/jotoho/waituntil/{start.kt => Start.kt} (67%) diff --git a/src/main/kotlin/de/jotoho/waituntil/start.kt b/src/main/kotlin/de/jotoho/waituntil/Start.kt similarity index 67% rename from src/main/kotlin/de/jotoho/waituntil/start.kt rename to src/main/kotlin/de/jotoho/waituntil/Start.kt index 7a4275c..b87355b 100644 --- a/src/main/kotlin/de/jotoho/waituntil/start.kt +++ b/src/main/kotlin/de/jotoho/waituntil/Start.kt @@ -7,28 +7,30 @@ import kotlin.system.exitProcess // See README.md and LICENSE.md for license information // Author: Jonas Tobias Hopusch (@jotoho) + val langGerman: String = Locale.GERMAN.language val applicationOutputLanguage: String = if (Locale.getDefault().language.equals(Locale.GERMAN.language)) - Locale.GERMAN.language - else Locale.ENGLISH.language + Locale.GERMAN.language + else Locale.ENGLISH.language + +// For accessing package information +object DummyClass fun main(args: Array) { - val optionDictionary = mapOf(Pair("-h", "--help")) + val optionDictionary = mapOf(Pair("-h", "--help"), Pair("-v", "--version")) val options = HashSet() val words = HashSet() for (arg in args) { if (arg.startsWith("--")) { - options.add(arg.substring(startIndex=2)) - } - else if (arg.startsWith('-')) { + options.add(arg.substring(startIndex = 2)) + } else if (arg.startsWith('-')) { if (optionDictionary.containsKey(arg)) - options.add(optionDictionary[arg]!!.substring(startIndex=2)) + options.add(optionDictionary[arg]!!.substring(startIndex = 2)) else System.err.println("Short-hand '$arg' does not exist. Ignoring!") - } - else + } else words.add(arg) } @@ -39,12 +41,18 @@ fun main(args: Array) { println("Help is yet to come. (Not implemented)") } } - } - else if (words.size == 1) { + } else if (options.contains("version")) { + when (applicationOutputLanguage) { + langGerman -> { + val thisPackage = DummyClass.javaClass.`package` + val appVersion = thisPackage.implementationVersion ?: "UNKNOWN" + println("waituntil version $appVersion") + } + } + } else if (words.size == 1) { val target = calculateAndAnnounceTargetTime(words.iterator().next()) waitUntilTimeStamp(target) - } - else { + } else { when (applicationOutputLanguage) { langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)") else -> {