-
Hi, I've created a cli app which dynamically sets up its subcommands and options based on a configuration file.
But I cannot figure out a straight forward way to get the value in
I have a few issues with this approach:
Is there a better way of getting the values from the Clikt supplied Options? Additionally, I can only think of one other way to make it work, which is to create my own implementation of Option and supply that. The problem with this approach is that it is not easy to implement and seems to require much more knowledge about the inner workings of Clikt than I possess, or than I care to learn as a library user. It would be great if there was some documentation or perhaps some facilities in Clikt, like a base class, making it easier to implement. Please advice. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
class C : CliktCommand() {
override fun run() {
registeredOptions().forEach {
echo("${it.names.joinToString()}: ${(it as? OptionDelegate<*>)?.value}")
}
}
}
with(C()) {
registerOption(option("--foo"))
main(emptyArray())
}
|
Beta Was this translation helpful? Give feedback.
OptionWithValues
, since that's the interface that definesvalue
. If it's not anOptionDelegate
, then it doesn't have a value.null
if they weren't provided.value
only throws an exception on access when you haven't calledparse
/main
, or if you access it afterparse
thrown an exception.