You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following scenario: A CLI with multiple subcommands with the main CLI having required options. Here is what I came up with:
fun main(args: Array<String>) {
MainCLI().subcommands(Sub1(), Sub2()).main(args)
}
class MainCLI : CliktCommand(allowMultipleSubcommands = true) {
private val optA: String by option("-a", "--opt-a", help = "My option 'A'").required()
override fun run() {
echo("Running main command, optA = $optA")
}
}
open class SubCLI : CliktCommand() {
private val optB: String by option("-b", "--opt-b", help = "My option 'B'").default("B")
override fun run() {
echo("Running subcommand ${this::class.simpleName}, optB = $optB")
}
}
class Sub1 : SubCLI()
class Sub2 : SubCLI()
When I run it like this:
main-cli --opt-a=X sub1 --opt-b=Y sub2 --opt-b=Z
I get the following output:
Running main command, optA = X
Running subcommand Sub1, optB = Y
Usage: main-cli [OPTIONS] COMMAND [ARGS]...
Error: Missing option "--opt-a".
I dug a bit with a debugger in hand and got to Parser.parse() It appears it is called several times:
I have the following scenario: A CLI with multiple subcommands with the main CLI having required options. Here is what I came up with:
When I run it like this:
I get the following output:
I dug a bit with a debugger in hand and got to Parser.parse() It appears it is called several times:
Due to my very limited knowledge in kotlin, I got stuck there.
What am I doing wrong?
The text was updated successfully, but these errors were encountered: