Paulo Cereda
07/28/2025, 7:00 PMinput to be influenced by a flag, so
private val caps by option("--caps").flag()
private val input by argument(name = "input").multiple(required = true).transformAll {
if (caps) it.map { i -> i.uppercase() } else it
}
I may be mistaken, but I vaguely remember seeing this sort of cross-dependency mentioned somewhere (was it in the documentation?). Any suggestions are welcome! Thanks! Update: check 🧵 .Paulo Cereda
07/28/2025, 7:13 PMThe lambdas you pass to(emphasis mine) So I gather my code works by accident, and this practice should be avoided? Thanks!are called after the values for all options and arguments have been set, so (unlike in transforms) you can reference other parametersvalidate
Paulo Cereda
07/28/2025, 7:28 PMprivate val caps by option("--caps").flag()
private val input by argument(name = "input").convert {
if (caps) it.uppercase() else it
}.multiple(required = true)
I get
Cannot read from option delegate before parsing command line
which was what I was expecting to get. 🙂 Then I found out about eager, so I could change caps to
private val caps by option("--caps", eager = true).flag()
and then the code works! 🎉 Is this the correct way then? Thanks!AJ Alt
09/04/2025, 7:55 PMconvert is supposed to be able to reference other options without needing eager. But it looks like there's a bug in the implementation of convert that should be easy to fix.Paulo Cereda
09/04/2025, 10:33 PM