Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass arguments to kotlin script?

I have a windows batch

@echo off

setlocal
  call kotlinc-jvm -cp "%~dp0\lib\commons-cli-1.3.1.jar" -script "%~dp0\RmMvnRepo.kts" %*
endlocal

If I pass "-h" option to the batch, kotlinc-jvm own's help will display. But I want my RmMvnRepo.kts to receive the option. How to do that?


EDIT: No need to answer this question anymore. I've found a bug in kotlinc related to this.

like image 654
Winter Young Avatar asked Dec 20 '15 04:12

Winter Young


1 Answers

Think of your code wrapped in main function. Then you can access arguments through args array.

Call the script with arguments
kotlinc -script ...kts "option1" "option2"
Access the arguments through args variable
println(args.size) // will output 2

Update: Try quotes to pass -h parameter

kotlinc -script ...kts "%*"
like image 177
Ruslan Avatar answered Nov 15 '22 08:11

Ruslan