@@ -99,8 +99,7 @@ fun main(args: Array<String>) {
9999 // Find all //DEPS directives and concatenate their values
100100 val dependencies = scriptText
101101 .filter { it.startsWith(" //DEPS " ) }
102- .map { it.split(" [ ]+" .toRegex())[1 ] }
103- .flatMap { it.split(" ;" , " ," , " " ) }
102+ .flatMap { it.split(" [ ;,]+" .toRegex()).drop(1 ) }
104103 .map(String ::trim)
105104
106105
@@ -114,10 +113,7 @@ fun main(args: Array<String>) {
114113 val classpath = resolveDependencies(dependencies)
115114
116115 // Extract kotlin arguments
117- val kotlinOpts = scriptText.
118- filter { it.startsWith(" //KOTLIN_OPTS " ) }.
119- flatMap { it.split(" " ).drop(0 ) }.
120- joinToString(" " )
116+ val kotlinOpts = extractKotlinOptions(scriptText)
121117
122118
123119 // Optionally enter interactive mode
@@ -221,15 +217,24 @@ fun main(args: Array<String>) {
221217
222218
223219 // print the final command to be run by exec
224- val shiftedArgs = args.drop(1 + args.indexOfFirst { it == scriptResource }).
225- // map { "\""+it+"\"" }.
226- joinToString(" " )
220+ val shiftedArgs = args.drop(1 + args.indexOfFirst { it == scriptResource }).joinToString(" " )
227221
228222 println (" kotlin ${kotlinOpts} -classpath ${jarFile}${CP_SEPARATOR_CHAR }${KOTLIN_HOME }${File .separatorChar} lib${File .separatorChar} kotlin-script-runtime.jar${CP_SEPARATOR_CHAR }${classpath} ${execClassName} ${shiftedArgs} " )
229223}
230224
225+
226+ private fun extractKotlinOptions (scriptText : List <String >): String {
227+ val koptsPrefix = " //KOTLIN_OPTS "
228+
229+ return scriptText.
230+ filter { it.startsWith(koptsPrefix) }.
231+ map { it.replace(koptsPrefix, " " ) }.
232+ joinToString(" " )
233+ }
234+
235+
231236/* * Determine the latest version by checking github repo and print info if newer version is availabe. */
232- fun versionCheck () {
237+ private fun versionCheck () {
233238
234239 // val latestVersion = fetchFromURL("https://git.io/v9R73")?.useLines {
235240 // val kscriptRawReleaseURL= "https://git.io/v9R73"
0 commit comments