Add --version commandline flag and support executable jar files with Gradle #12

Merged
jotoho merged 4 commits from version-and-fat-jars into master 2021-09-19 22:18:15 +02:00
Showing only changes of commit 09cf7a9168 - Show all commits

View file

@ -7,28 +7,30 @@ import kotlin.system.exitProcess
// See README.md and LICENSE.md for license information // See README.md and LICENSE.md for license information
// Author: Jonas Tobias Hopusch (@jotoho) // Author: Jonas Tobias Hopusch (@jotoho)
val langGerman: String = Locale.GERMAN.language val langGerman: String = Locale.GERMAN.language
val applicationOutputLanguage: String = if (Locale.getDefault().language.equals(Locale.GERMAN.language)) val applicationOutputLanguage: String = if (Locale.getDefault().language.equals(Locale.GERMAN.language))
Locale.GERMAN.language Locale.GERMAN.language
else Locale.ENGLISH.language else Locale.ENGLISH.language
// For accessing package information
object DummyClass
fun main(args: Array<String>) { fun main(args: Array<String>) {
val optionDictionary = mapOf(Pair("-h", "--help")) val optionDictionary = mapOf(Pair("-h", "--help"), Pair("-v", "--version"))
val options = HashSet<String>() val options = HashSet<String>()
val words = HashSet<String>() val words = HashSet<String>()
for (arg in args) { for (arg in args) {
if (arg.startsWith("--")) { if (arg.startsWith("--")) {
options.add(arg.substring(startIndex=2)) options.add(arg.substring(startIndex = 2))
} } else if (arg.startsWith('-')) {
else if (arg.startsWith('-')) {
if (optionDictionary.containsKey(arg)) if (optionDictionary.containsKey(arg))
options.add(optionDictionary[arg]!!.substring(startIndex=2)) options.add(optionDictionary[arg]!!.substring(startIndex = 2))
else else
System.err.println("Short-hand '$arg' does not exist. Ignoring!") System.err.println("Short-hand '$arg' does not exist. Ignoring!")
} } else
else
words.add(arg) words.add(arg)
} }
@ -39,12 +41,18 @@ fun main(args: Array<String>) {
println("Help is yet to come. (Not implemented)") println("Help is yet to come. (Not implemented)")
} }
} }
} 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) { }
} else if (words.size == 1) {
val target = calculateAndAnnounceTargetTime(words.iterator().next()) val target = calculateAndAnnounceTargetTime(words.iterator().next())
waitUntilTimeStamp(target) waitUntilTimeStamp(target)
} } else {
else {
when (applicationOutputLanguage) { when (applicationOutputLanguage) {
langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)") langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)")
else -> { else -> {