Skip to content

Commit adc632c

Browse files
committed
impl support for @file:KotlinOpts
1 parent a4d80f3 commit adc632c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ fun collectRuntimeOptions(scriptText: List<String>): String {
253253
filter { it.startsWith(koptsPrefix) }.
254254
map { it.replaceFirst(koptsPrefix, "").trim() }
255255

256-
//todo add support for @file:KotlinOpts here
256+
//support for @file:KotlinOpts see #47
257+
val annotatonPrefix = "@file:KotlinOpts("
258+
kotlinOpts += scriptText
259+
.filter { it.startsWith(annotatonPrefix) }
260+
.map { it.replaceFirst(annotatonPrefix, "").split(")")[0] }
261+
.map { it.trim(' ', '"') }
262+
257263

258264
// Append $KSCRIPT_KOTLIN_OPTS if defined in the parent environment
259265
System.getenv()["KSCRIPT_KOTLIN_OPTS"]?.run {

src/test/kotlin/Tests.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ class Tests {
5656
collectRuntimeOptions(lines) shouldBe "-foo 3 'some file.txt' --bar"
5757
}
5858

59+
@Test
60+
fun annotOptsCollect() {
61+
val lines = listOf(
62+
"//KOTLIN_OPTS -foo 3 'some file.txt'",
63+
"""@file:KotlinOpts("--bar")"""
64+
)
65+
66+
collectRuntimeOptions(lines) shouldBe "-foo 3 'some file.txt' --bar"
67+
}
68+
5969

6070
@Test
6171
fun foo() {

0 commit comments

Comments
 (0)