clikt icon indicating copy to clipboard operation
clikt copied to clipboard

Env vars are not bound when `CoreCliktCommand` is used

Open JakeWharton opened this issue 3 months ago • 1 comments

CliktCommand works fine. CoreSuspendingCliktCommand also broken.

Works:

fun main(vararg args: String) {
	ExampleCommand().main(args)
}

private const val envVarName = "THIS_IS_A_TEST"

private class ExampleCommand : CliktCommand() {
	private val value by option(envvar = envVarName)

	override fun run() {
		println("env: " + System.getenv(envVarName))
		println("property: $value")
	}
}
❯ gw -q installDist && THIS_IS_A_TEST=hello ./build/install/clikt-env-vars/bin/clikt-env-vars
env: hello
property: hello

Does not work:

fun main(vararg args: String) {
	ExampleCommand().main(args)
}

private const val envVarName = "THIS_IS_A_TEST"

private class ExampleCommand : CoreCliktCommand() {
	private val value by option(envvar = envVarName)

	override fun run() {
		println("env: " + System.getenv(envVarName))
		println("property: $value")
	}
}
❯ gw -q installDist && THIS_IS_A_TEST=hello ./build/install/clikt-env-vars/bin/clikt-env-vars
env: hello
property: null

JakeWharton avatar Sep 05 '25 03:09 JakeWharton

Okay so this is documented: https://ajalt.github.io/clikt/advanced/#core-module

However, it seems like Mordant really should not be required for most of these things. Reading env vars in a multiplatform context is a few lines. Reading files is more lines, but not a ridiculous amount of lines. In that list, the only thing that screams Mordant to me is "Text wrapping, formatting, markdown, or color support".

Can we work to move the others into having core support?

JakeWharton avatar Sep 05 '25 03:09 JakeWharton