clikt
clikt copied to clipboard
Can't set context
class HelloWorld : CliktCommand() {
init {
context { readArgumentFile = null }
}
val foo by option("--foo", "-f").required()
override fun run() {
println("Hello, $foo")
}
}
HelloWorld().context { readArgumentFile = null }.main(args)
None of the context overrides works.
./github.main.kts --foo @types/node
warning: argfile not found: /Users/foobar/development/github.com/project/types/node
Usage: hello-world [<options>]
Error: option --foo requires a value
Hm, I can't reproduce this. If I run your exact code, I get Hello, @types/node. There's also a unit test for this. Are you on the latest version of Clikt?
Yes I am using 5.0.3. I tested a little bit more but I couldn't figured it out...
We are using Kotlinscript.
#!/usr/bin/env kotlin
@file:DependsOn("com.github.ajalt.clikt:clikt-jvm:5.0.3")
class C : CliktCommand() {
init {
context { readArgumentFile = null }
}
val arg by option("--arg")
override fun run() {
println(arg)
}
}
C().main(listOf("--arg", "@asd"))
./github.main.kts
@asd
./github.main.kts --arg @asd
warning: argfile not found: /Users/user/development/github.com/org/repo/asd
@asd
The warning should not come at all, because we don't use args in the code, or?
Does this only happen with kotlinscript? Can you try it with a regular project?