https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
scripting
  • i

    igor.wojda

    04/15/2020, 9:25 AM
    Is possible to retrieve path to the directory where script is located? (I am talking about actual directory on disk, not working cmd directory that can be retrieved by
    System.getProperty("user.dir")
    )
    i
    • 2
    • 3
  • s

    Slackbot

    04/17/2020, 12:36 PM
    This message was deleted.
    x
    • 2
    • 4
  • k

    keturn

    04/23/2020, 7:04 PM
    I'm giving scripting a try and am not yet clear on the different modes there seem to be. The things IDEA has "new file" interfaces for are "Script" and "Worksheet" (
    .ws.kts
    ), but do I need
    .main.kts
    instead of
    .ws.kts
    to use dependencies?
    i
    • 2
    • 1
  • g

    gammanik

    04/24/2020, 2:36 PM
    Hello. I have a problem with
    ClassLoaders
    and
    scriptEngine
    . Im creating a scriptEngine and adding my dsl rules in there from the outer scope
    File("/Users/Nikita/Documents/lib-support/dsl-lib-support/build/libs/dsl-lib-support.jar")
    My script returns me Map<String, MethodToMark>. MethodToMark is a part of my dsl rules:
    val res: Map<String, MethodToMark>? = engine.eval(script) as Map<String, MethodToMark>?
    println(res!!["lib.LibClassOne.method1"] as MethodToMark)
    But this code doesn’t work. When I’m calling
    res!!["lib.LibClassOne.method1"] as MethodToMark
    it gives me an error:
    java.lang.ClassCastException: class MethodToMark cannot be cast to class MethodToMark (MethodToMark is in unnamed module of loader <http://java.net|java.net>.URLClassLoader @79609006; MethodToMark is in unnamed module of loader <http://com.intellij.ide.plugins.cl|com.intellij.ide.plugins.cl>.PluginClassLoader @67f6ebd8)
    So the problem is that I cannot cast cast the same class to itself because of the fifferent class loaders I guess. Here is a come Image where I’m creating my scriptEngine and adding my dsl rules: How do I solve it?
    i
    • 2
    • 2
  • i

    iguissouma

    04/26/2020, 7:58 AM
    @gammanik dsl-lib-support.jar is it included in your plugin?
    g
    • 2
    • 9
  • a

    addamsson

    04/26/2020, 3:40 PM
    I have the following script:
    import kotlinx.serialization.Serializable
    import kotlinx.serialization.json.Json
    import kotlinx.serialization.json.JsonConfiguration
    
    @Serializable
    data class User(
        val name: String
    )
    
    val user = User("jon")
    
    val json = Json(JsonConfiguration.Stable)
    
    val jsonData = json.stringify(User.serializer(), user)
    
    val result = json.parse(User.serializer(), jsonData)
    
    require(user == result)
    which I try to run in a script but I get the following error:
    ERROR Unresolved reference: serializer
    I guess the problem is that this works with `kotlinx.serialization`'s annotation processing feature. Is it possible to get this working in a script? This is how I run it:
    private fun evalFile(scriptFile: File): ResultWithDiagnostics<EvaluationResult> {
        val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<TestScript> {
            jvm {
                dependenciesFromCurrentContext(wholeClasspath = true)
            }
        }
        val evalConfig = createJvmEvaluationConfigurationFromTemplate<TestScript> {
            jvm {
                this.mainArguments.put(arrayOf("1"))
            }
        }
    
        return BasicJvmScriptingHost().eval(scriptFile.toScriptSource(), compilationConfiguration, evalConfig)
    }
    i
    • 2
    • 2
  • m

    MrPowerGamerBR

    05/09/2020, 11:15 AM
    What can cause slow compile times for scripts? For some reason compiling a ~600 script file is taking almost 2.4 minutes! Is there's anything that could cause such long times? (Example: Wildcard imports, a lot of dependencies in the classpath, etc)
    • 1
    • 1
  • e

    edwinRNDR

    05/10/2020, 10:32 AM
    Hey, just wanted to share some of my work using kotlin scripting: https://openrndr.discourse.group/t/improved-live-coding-with-orx-olive/106 and

    https://www.youtube.com/watch?v=qdgnRct0_nw&amp;feature=youtu.be&amp;t=12428▾

    n
    l
    • 3
    • 20
  • j

    J-P

    05/13/2020, 1:15 AM
    Dear All, does somebody know whether is is possible to open the REPL with a pre-loaded script template ? It would be great to open the REPL and then be able to execute (interactive) script commands as if I were writing a script within my extension. At the minimum, I would need to open the REPL with some pre-loaded imports so that script objects and functions are recognized.
    a
    i
    • 3
    • 5
  • m

    mr_kay

    05/20/2020, 6:51 PM
    Hi all, I am trying to pass an argument to a KotlinScript (1.3.72) but it seems the generated script class has only a default constructor
    @KotlinScript(
        fileExtension = "siteCost.kts", 
        compilationConfiguration = SiteCostScriptCompilationConfiguration::class,
        evaluationConfiguration = SiteCostScriptEvaluationConfiguration::class
    )
    abstract class SiteCostScript(val arg: String)
    for the time being, the constructor arg is directly passed in the `EvaluationConfiguration`:
    object SiteCostScriptEvaluationConfiguration : ScriptEvaluationConfiguration({
        constructorArgs("hugo")
    })
    however, if the script is evaluated using the following code
    fun <T> eval(scriptString: String, resultClass: Class<T>): T {
            val jvmScriptingHost = BasicJvmScriptingHost().eval(
                scriptString.toScriptSource(),
                SiteCostScriptCompilationConfiguration,
                SiteCostScriptEvaluationConfiguration
            )
            return (resultWithDiag.valueOrThrow().returnValue as ResultValue.Value).value as T  
        }
    I get an Exception (abbreviated)
    java.lang.RuntimeException: java.lang.IllegalArgumentException: wrong number of arguments
    	at kotlin.script.experimental.api.ErrorHandlingKt.valueOrThrow(errorHandling.kt:240)
    	at com.zitecs.ologis.modules.ologisscriptengine.sitecost.control.kotlinscripting.SiteCostScriptingHost.eval(SiteCostScriptingHost.kt:19)
    	at com.zitecs.ologis.modules.ologisscriptengine.sitecost.control.kotlinscripting.SiteCostScriptingHostTest.return ScCostAssessment(SiteCostScriptingHostTest.kt:40)
        ....
    	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
    Caused by: java.lang.IllegalArgumentException: wrong number of arguments
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    	at kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.evalWithConfigAndOtherScriptsResults(BasicJvmScriptEvaluator.kt:95)
    It seems
    BasicJvmScriptEvaluator.evalWithConfigAndOtherScriptsResults
    tries to invoke a default constructor (without args) which does not exist. What am I doing wrong? Am I supposed to implement my own
    ScriptEvaluator
    ?
    ✔️ 2
    • 1
    • 1
  • l

    louiscad

    05/24/2020, 8:06 PM
    Hello! I have a Kotlin script with maven dependencies, and I'd like to clear their cache because despite me removing the maven local repo, it keeps on using an outdated version that I even removed from my
    ~./m2
    local repo, which didn't match what I released on a bintray repo. How can I proceed without wiping my whole computer?
    m
    i
    • 3
    • 3
  • j

    jdemeulenaere

    05/26/2020, 7:06 AM
    Is it a
    .main.kts
    script ? If yes you can look at the script definition: https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-main-kts/src/org/jetbrains/kotlin/mainKts/scriptDef.kt#L70
    l
    i
    • 3
    • 4
  • p

    Paul Woitaschek

    05/29/2020, 1:54 PM
    I have a .main.kts and want to run it from the command line. It has a shebang:
    #!/usr/bin/env kotlin
    . This works fine but when I want to call it with arguments I always have to put a
    --
    first because else the commands are passed to kotlin and not to the script. I.e.
    ./my_script.main.kts -- --my-flag
    Is there a way to define this so I dont have to call
    --
    first?
    m
    • 2
    • 3
  • t

    Tmpod

    05/31/2020, 2:16 PM
    Hey! Checking back in scripting and wondering what's the status on applying compiler plugins
    i
    • 2
    • 1
  • d

    Daren Klamer

    06/08/2020, 3:43 AM
    the source is this
    class Lamp {
                                
                                    // property (data member)
                                    private var isOn: Boolean = false
                                
                                    // member function
                                    fun turnOn() {
                                        isOn = true
                                    }
                                
                                    // member function
                                    fun turnOff() {
                                        isOn = false
                                    }
                                
                                    fun displayLightStatus(lamp: String) {
                                        if (isOn == true)
                                            println("\$lamp lamp is on.")
                                        else
                                            println("\$lamp lamp is off.")
                                    }
                                }
                                
                                fun main(args: Array<String>) {
                                
                                    val l1 = Lamp() // create l1 object of Lamp class
                                    val l2 = Lamp() // create l2 object of Lamp class
                                
                                    l1.turnOn()
                                    l2.turnOff()
                                
                                    l1.displayLightStatus("l1")
                                    l2.displayLightStatus("l2")
                                }
    e
    • 2
    • 1
  • s

    SrSouza

    06/13/2020, 6:37 PM
    Hi @ilya.chernikov with the new IR Compiler will make easy to Coroutines be supported in Scripting, maybe the compiler is not the case that suspend is not yet supported, but over all, the IR will make it easy to be implemented?
    i
    • 2
    • 1
  • p

    Paul Woitaschek

    06/16/2020, 8:38 AM
    #!/usr/bin/env kotlin
    @file:CompilerOptions("-Xopt-in=kotlin.time.ExperimentalTime","-jvm-target=1.8")
    @file:DependsOn("com.github.ajalt:clikt:2.7.1")
    
    import com.github.ajalt.clikt.core.CliktCommand
    import com.github.ajalt.clikt.parameters.options.option
    import com.github.ajalt.clikt.parameters.options.required
    import com.github.ajalt.clikt.parameters.types.enum
    
    enum class RPS {
      Rock
    }
    
    class Application : CliktCommand(){
    
      private val rps : RPS by option("--rps").enum<RPS>().required()
    
      override fun run() {
        println(rps)
      }
    }
    
    Application().main(args)
    This doesn't compile:
    ➜  scripts git:(features/huawei_health) ✗ ./test.main.kts -- --rps rock
    error: cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option (test.main.kts:16:44)
    test.main.kts:16:44: error: cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option
      private val rps : RPS by option("--rps").enum<RPS>().required()
    i
    • 2
    • 1
  • d

    Daren Klamer

    06/16/2020, 12:05 PM
    val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<Any> {
                compilerOptions("-jvm-target", "1.8", "-Xnew-inference", "-Xinline-classes")
                jvm {
                    if (classLoader != null) {
                        dependenciesFromClassloader(
                            classLoader = classLoader,
                            wholeClasspath = true
                        )
                    } else {
                        dependenciesFromCurrentContext(
                            wholeClasspath = true
                        )
                    }
                    providedProperties(typeMap)
                }
                hostConfiguration(ScriptingHostConfiguration {
                    jvm {
                        val cacheExtSetting = System.getProperty(COMPILED_SCRIPTS_CACHE_DIR_PROPERTY)
                            ?: System.getenv(COMPILED_SCRIPTS_CACHE_DIR_ENV_VAR)
                        val cacheBaseDir = when {
                            cacheExtSetting == null -> System.getProperty("java.io.tmpdir")
                                ?.let(::File)?.takeIf { it.exists() && it.isDirectory }
                                ?.let { File(it, "main.kts.compiled.cache").apply { mkdir() } }
                            cacheExtSetting.isBlank() -> null
                            else -> File(cacheExtSetting)
                        }?.takeIf { it.exists() && it.isDirectory }
                        //cacheBaseDir = File("/tmp")
                        if (cacheBaseDir != null)
                            compilationCache(
                                CompiledScriptJarsCache { script, scriptCompilationConfiguration ->
                                    File(cacheBaseDir,
                                        compiledScriptUniqueName(script, scriptCompilationConfiguration) + ".jar")
                                }
                            )
                    }
                })
            }
    i
    • 2
    • 1
  • n

    Nikky

    06/20/2020, 1:23 PM
    I tried to make a ,kts script that uses
    kotlinx-html
    to build a website it seems to hang during compilation, 5 minutes and still hanging, first guess is too many functions with lambdas, this is the code: https://gist.github.com/9d9cfa8dd17ad7650d4fbf203e0f2607 short tests of 10-20 lines and just a few things seemed to work fine
    i
    • 2
    • 1
  • s

    SrSouza

    06/26/2020, 10:06 PM
    Hi @ilya.chernikov, I have embedded definition of the script inside my IntelliJ plugin but ScriptDefinitionsProvider only support jar files as classpath, there is anyway to use the current classpath to find the definition?
    i
    • 2
    • 2
  • s

    SrSouza

    06/29/2020, 9:26 PM
    Two questions about the dependencies resolver. 1. I test the IvyResolver at my script definition and works great, but I notice a long freeze in my IDEA when it load the dependencies. This is a know issue? There is anyway to not freeze and show a load bar at the bottom? Like the Gradle sync taks. 2. I saw that the there is a Maven Resolver separated module, the IvyResolver could be one too? I'm using it because the Ivy library is more lightweight them the maven aether that kotlin-scripting-dependencies-maven uses.
    i
    • 2
    • 1
  • s

    SrSouza

    07/01/2020, 2:05 AM
    Hi folks, can you help me with something about the IntelliJ and Scripts? I want to my script have the extension:
    bk.kts
    and I try to create a New File Action at the IntelliJ and my extension is beeing removed, any work around or there is a better way to do that?
    i
    • 2
    • 4
  • m

    Matthieu Stombellini

    07/01/2020, 3:13 PM
    Hi, while trying to use
    JvmScriptCompiler
    the Kotlin compiler complained about not finding
    ScriptCompilerProxy
    in the classpath. I'm using
    kotlin-scripting-jvm-host-embeddable
    and I had to add
    kotlin-scripting-compiler-embeddable
    as a dependency as well for the Kotlin compiler to find it. Is this normal? (1.3.72)
    i
    • 2
    • 2
  • m

    Matthieu Stombellini

    07/01/2020, 3:45 PM
    Also, the compilation fails if the SourceCode object's
    name
    has a dot in it -- is this specified anywhere? (it failed in a weird way for me, it didn't detect the implicit receivers i set in the compilation configuration at all)
    i
    • 2
    • 2
  • s

    SrSouza

    07/03/2020, 11:23 PM
    Hi @ilya.chernikov, in the previous versions I use
    actualClassLoader
    in the Evaluation Configuration, but now, it is not available with public access, there is any alternative to it? to load the script in a my custom classloader?
    i
    • 2
    • 4
  • e

    Egor

    07/06/2020, 10:04 AM
    Hi, @ilya.chernikov . I use kotlin scripts in our project. We have different versions of the script in that project. Every version resides in different package. For example: packageA | --> myscript.kts packageB | --> myscript.kts When I try to build the project I get :
    Duplicate JVM class name 'B_main' generated from: Myscript, Myscript
    error. In this case I used gradle for the build. I tried with it with custom Kotlin script template as well as with ‘main.kts’ template. The result is the same. I checked in gradle
    build
    directory and saw that script generated classes resides on the top level and not in separate packages (
    packageA
    and
    packageB
    ). How can I fix it?
    i
    • 2
    • 4
  • d

    Dan T

    07/07/2020, 10:49 PM
    New scripting user question: I'm wondering about the current status of IDE support for running and debugging kts scripts. e.g. `foo.main.kts`:
    #!/usr/bin/env kotlin
    
    println("foo")
    fails in IntelliJ 2020.1.2 with the following error:
    error: org/jetbrains/kotlin/scripting/compiler/plugin/impl/KJvmCompiledModuleInMemory (foo.main.kts): java.lang.NoClassDefFoundError: org/jetbrains/kotlin/scripting/compiler/plugin/impl/KJvmCompiledModuleInMemory
    I tried the
    1.8
    and
    11.0.5
    as JDKs. Is this something that should be working currently? If not, is there an issue/page to track the progress of this? Thanks.
    i
    • 2
    • 2
  • s

    SrSouza

    07/09/2020, 4:16 AM
    If you want to check the current state of my ScriptDef that I found this two issues, is in the Github: https://github.com/DevSrSouza/Bukkript/blob/master/script-definition/src/main/kotlin/br/com/devsrsouza/bukkript/script/definition/ScriptDef.kt
    i
    • 2
    • 16
  • e

    efemoney

    07/09/2020, 9:48 AM
    Maybe worth mentioning but I noticed in 1.4-M3,
    jvm-host-embeddable
    has been removed (renamed?) in favor of
    jvm-host-unshaded
    . Is this a simple artifact name change or are there other more detailed changes under the hood?
    i
    • 2
    • 2
  • j

    jw

    07/13/2020, 12:32 PM
    How do I pass
    --
    flags as arguments to a script? They are interpreted by kotlin rather than passed as arguments to my script. I tried using
    env -S kotlin --
    as my shebang but
    kotlin
    doesn't seem to support
    --
    👀 1
    k
    • 2
    • 4
Powered by Linen
Title
j

jw

07/13/2020, 12:32 PM
How do I pass
--
flags as arguments to a script? They are interpreted by kotlin rather than passed as arguments to my script. I tried using
env -S kotlin --
as my shebang but
kotlin
doesn't seem to support
--
👀 1
e.g.,
$ ./test.main.kts --debug
error: invalid argument: --debug
info: use -help for more information
Filed https://youtrack.jetbrains.com/issue/KT-40257
k

kenkyee

07/14/2020, 10:58 AM
Try using this library... Been pretty happy with it used with kscript: https://ajalt.github.io/clikt/
j

jw

07/14/2020, 5:01 PM
Yes i use clikt everywhere, but the problem was about kotlin intercepting arguments before they even made it into the
args
array
👍 2
View count: 2