Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print the help message from subcommand #93

Open
grahamjenson opened this issue Jan 9, 2023 · 2 comments
Open

Print the help message from subcommand #93

grahamjenson opened this issue Jan 9, 2023 · 2 comments

Comments

@grahamjenson
Copy link

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.

@SvyatoslavScherbina
Copy link
Contributor

Hello.
Is your feature request the same as #60?

@gravitylow
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants