Skip to content

Is it possible to group subcommands in help outout? #498

Closed Answered by ajalt
jacobk asked this question in Q&A
Discussion options

You must be logged in to vote

So one option is to write the grouped commands in the root command help manually, which is what git does. But if you want to automate it, it's not too hard to customize the help formatter to group subcommands by using e.g. a help tag to specify the group:

class MyHelpFormatter(context: Context) : MordantHelpFormatter(context) {
    override fun shouldShowTag(tag: String, value: String): Boolean {
        return super.shouldShowTag(tag, value) && tag != "group"
    }

    override fun renderCommands(parameters: List<ParameterHelp>): List<RenderedSection> {
        val grouped = parameters.filterIsInstance<ParameterHelp.Subcommand>()
            .groupBy { it.tags["group"] }
        return

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jacobk
Comment options

Answer selected by ajalt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants