Skip to content

Commit b25fbb1

Browse files
committed
build: updated bugfix version
refactor: more strict OS type checking
1 parent d166a04 commit b25fbb1

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/main/kotlin/kscript/app/Kscript.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import org.docopt.DocOptWrapper
1818
* @author Marcin Kuszczak
1919
*/
2020

21-
const val KSCRIPT_VERSION = "4.0.2"
21+
const val KSCRIPT_VERSION = "4.0.3"
2222

2323
fun main(args: Array<String>) {
2424
try {

src/main/kotlin/kscript/app/model/OsType.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ enum class OsType(val osName: String) {
88
fun isUnixHostedOnWindows() = (this == CYGWIN || this == MSYS)
99

1010
companion object {
11-
fun findOrThrow(name: String) =
12-
//Exact comparison (it.osName.equals(name, true)) seems to be not feasible as there is also e.g. "darwin21"
13-
//and maybe even other osTypes: specific versions of os'es shouldn't belong to OsType.
14-
values().find { name.contains(it.osName, true) } ?: throw IllegalArgumentException("Unsupported OS: $name")
11+
fun findOrThrow(name: String): OsType {
12+
// Exact comparison (it.osName.equals(name, true)) seems to be not feasible as there is also e.g. "darwin21"
13+
// "darwin19" and maybe even other osTypes. It seems though that startsWith() is covering all cases.
14+
// https://github.com/holgerbrandl/kscript/issues/356
15+
return values().find { name.startsWith(it.osName, true) }
16+
?: throw IllegalArgumentException("Unsupported OS: $name")
17+
}
1518
}
1619
}

0 commit comments

Comments
 (0)