commons: add OS tool

This commit is contained in:
Johannes Frohnmeyer 2022-10-13 20:56:22 +02:00
parent dd973d64cd
commit 2477a799db
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package io.gitlab.jfronny.scripts
object OS {
val TYPE: Type = with(System.getProperty("os.name", "generic").toLowerCase()) {
when {
contains("mac") || contains("darwin") -> Type.MAC_OS
contains("win") -> Type.WINDOWS
contains("nux") -> Type.LINUX
else -> throw UnsupportedOSException()
}
}
enum class Type(val displayName: String, val codename: String) {
WINDOWS("Windows", "windows"),
MAC_OS("OSX", "macos"),
LINUX("Linux", "linux");
}
class UnsupportedOSException() : RuntimeException("Unrecognized OS")
}