From 2477a799dbd1fc64b0e22d2797c355db1d9ec010 Mon Sep 17 00:00:00 2001 From: JFronny Date: Thu, 13 Oct 2022 20:56:22 +0200 Subject: [PATCH] commons: add OS tool --- .../kotlin/io/gitlab/jfronny/scripts/OS.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 convention/src/main/kotlin/io/gitlab/jfronny/scripts/OS.kt diff --git a/convention/src/main/kotlin/io/gitlab/jfronny/scripts/OS.kt b/convention/src/main/kotlin/io/gitlab/jfronny/scripts/OS.kt new file mode 100644 index 0000000..a3a0cb3 --- /dev/null +++ b/convention/src/main/kotlin/io/gitlab/jfronny/scripts/OS.kt @@ -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") +} \ No newline at end of file