kotlinx-cli
kotlinx-cli copied to clipboard
Print the help message from subcommand
The makeUsage command is private
it should be protected
so that sub classes can call it.
My usecase is that I have a subcommand that itself has subcommands, and if executed without a subcommand I want it to print the help message, e.g. cli sc
prints help cli sc ssc
does something.
My workaround is this.
import kotlinx.cli.*
import kotlin.reflect.full.*
class NewSubCommand: Subcommand("sc", "sc") {
override fun execute() {
// Print Help
ArgParser::class.declaredFunctions.find { it.name == "makeUsage" }?.let {
println(it.call(tiz))
}
}
}
Another workaround might be to throw an error with:
override fun execute() {
throw ParsingException("Needs Sub command")
}
but I think this is also not a great workaround.
Hello. Is your feature request the same as https://github.com/Kotlin/kotlinx-cli/issues/60?
Looks to be a possible solution for #60. Thanks for the workarounds, the first worked well for me (slight typo, should be this
instead of tiz
I think)