Merge pull request 'Add --version commandline flag and support executable jar files with Gradle' (#12) from version-and-fat-jars into master

Reviewed-on: https://gitea.jotoho.de/jotoho/waituntil/pulls/12
This commit is contained in:
Jonas Tobias Hopusch 2021-09-19 22:18:13 +02:00
commit e11d3ead97
Failed to generate hash of commit
4 changed files with 36 additions and 14 deletions

1
.gitignore vendored
View file

@ -39,3 +39,4 @@ build
/de/jotoho/
/META-INF
/.idea
*.zst

View file

@ -6,6 +6,9 @@ plugins {
// Apply the application plugin to add support for building a CLI application in Java.
application
// For generating fat jars
id("com.github.johnrengelman.shadow") version "latest.release"
}
group = "de.jotoho"
@ -39,6 +42,16 @@ tasks.test {
useJUnitPlatform()
}
tasks.jar {
manifest {
attributes(
"Implementation-Title" to "waituntil",
"Implementation-Version" to "${project.version}",
"Main-Class" to "de.jotoho.waituntil.StartKt"
)
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "16"
}

View file

@ -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
// For accessing package information
object DummyClass
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 words = HashSet<String>()
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<String>) {
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())
waitUntilTimeStamp(target)
}
else {
} else {
when (applicationOutputLanguage) {
langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)")
else -> {

View file

@ -6,7 +6,7 @@ import java.time.LocalTime
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.util.TimeZone
import java.util.*
fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime {
val userTimeInputRelative = LocalTime.parse(userTimeInputRaw)