File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed
Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,11 @@ fun main(args: Array<String>) {
5757 quit(0 )
5858 }
5959
60- val docopt = DocOptWrapper (args, USAGE )
60+ // note: with current impt we still don't support `kscript -1` where "-1" is a valid kotlin expression
61+ val userArgs = args.dropWhile { it.startsWith(" -" ) }.drop(1 )
62+ val kscriptArgs = args.take(args.size - userArgs.size)
63+
64+ val docopt = DocOptWrapper (kscriptArgs, USAGE )
6165 val loggingEnabled = ! docopt.getBoolean(" silent" )
6266
6367
@@ -239,9 +243,10 @@ fun main(args: Array<String>) {
239243
240244
241245 // print the final command to be run by exec
242- val shiftedArgs = args.drop(1 + args.indexOfFirst { it == scriptResource }).joinToString(" " )
246+ // val joinedUserArgs = args.drop(1 + args.indexOfFirst { it == scriptResource }).joinToString(" ")
247+ val joinedUserArgs = userArgs.joinToString(" " )
243248
244- 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 } " )
249+ println (" kotlin ${kotlinOpts} -classpath ${jarFile}${CP_SEPARATOR_CHAR }${KOTLIN_HOME }${File .separatorChar} lib${File .separatorChar} kotlin-script-runtime.jar${CP_SEPARATOR_CHAR }${classpath} ${execClassName} ${joinedUserArgs } " )
245250}
246251
247252fun collectDependencies (scriptText : List <String >): List <String > {
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import java.io.File
88 */
99
1010/* * Simple Kotlin facade for org.org.docopt.Docopt.Docopt(java.lang.String) .*/
11- class DocOptWrapper (args : Array <String >, val usage : String ) {
11+ class DocOptWrapper (args : Iterable <String >, val usage : String ) {
1212
1313 val parsedArgs = try {
1414 Docopt (usage).withExit(false ).parse(args.toList())
Original file line number Diff line number Diff line change @@ -39,6 +39,11 @@ assert "kscript ''" ""
3939assert ' kscript "println(1+1)"' ' 2'
4040
4141
42+ # # use dashed arguments (to prevent regression from https://github.com/holgerbrandl/kscript/issues/59)
43+ assert ' kscript "println(args.joinToString(\"\"))" --arg u ments' ' --arguments'
44+ assert ' kscript -s "println(args.joinToString(\"\"))" --arg u ments' ' --arguments'
45+
46+
4247# # provide script via stidin
4348assert " echo 'println(1+1)' | kscript -" " 2"
4449
@@ -90,7 +95,7 @@ assert_end script_input_modes
9095# assert "kscript -i '//DEPS log4j:log4j:1.2.14'" "To create a shell with script dependencies run:\nkotlinc -classpath '${HOME}/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar'"
9196# assert "kscript -i <(echo '//DEPS log4j:log4j:1.2.14')" "To create a shell with script dependencies run:\nkotlinc -classpath '${HOME}/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar'"
9297
93- assert_end cli_helper_tests
98+ # assert_end cli_helper_tests
9499
95100# #######################################################################################################################
96101# # environment_tests
You can’t perform that action at this time.
0 commit comments