https://kotlinlang.org logo
#clikt
Title
# clikt
s

Simon Marquis

11/14/2023, 11:09 AM
👋 Hi, I'm trying to find a way to mix enum option using
multiple()
and
prompt()
to allow the user to provide values at runtime if nothing is provided. Unfortunately, this does not seem to be supported. What would be the recommended way to support this kind of behavior? I'm currently using this, but this prevent me from using a prompt
Copy code
val flavors: Set<Flavor> by option("-f", "--flavors")
    .enum<Flavor>(ignoreCase = true)
    .multiple(default = listOf(Main)).unique()
a

AJ Alt

11/14/2023, 4:56 PM
That particular combo isn't built in, but you can do it yourself easily.
mutliple
is just
transformAll { it }
, and
prompt
is just
transformAll { it.lastOrNull() ?: terminal.prompt("") }
, so you can combine them like
option().enum<>().transformAll { it.ifEmpty { listOf(terminal.prompt("..."))} }
👀 1
s

Simon Marquis

11/14/2023, 5:16 PM
Interesting, I'll try that. Thanks a lot. btw, that is an awesome lib that you built 👌
❤️ 1
I'm missing an import resolution on a
getValue
ReadOnlyProperty 🤔
My bad, I forgot to convert it back to a
Set
👍