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

Show help if no subcommands provided #60

Open
sviridov-alexey opened this issue Apr 27, 2021 · 9 comments
Open

Show help if no subcommands provided #60

sviridov-alexey opened this issue Apr 27, 2021 · 9 comments

Comments

@sviridov-alexey
Copy link
Contributor

It would be nice to have an option to show the help of the subcommand if no options and no subcommands are specified.

@LepilkinaElena
Copy link

Please, could you clarify? If there are subcommands you would like to get help message for each of these subcommands?

If we have test command and subcommands a, b, c. Then you want to have an option test --help-detailed that shows not only list of subcommands, but all flags for each of a, b, c?

@sviridov-alexey
Copy link
Contributor Author

sviridov-alexey commented Apr 27, 2021

Not exactly, I want to get same effect like "-h" option when no any option is given. I.e.

command subcommand

should act like

command subcommand -h

@sviridov-alexey
Copy link
Contributor Author

This is replated to subcommand with only possible subcommand, without arguments and options

@LepilkinaElena
Copy link

But if subcommand can be executed without any options? It can have all options with default values.

@sviridov-alexey
Copy link
Contributor Author

But if subcommand can be executed without any options? It can have all options with default values.

Generally speaking yes, but on the other hand, there isn't any possibility to show help for such "umbrella" subcommand, because makeUsage is internal, same as printAndTerminate. Also, I can't detect in execute method, was nested sumcommand present or not

@andylamax
Copy link

this would easily be achieved by just making makeUsage public. So that those who need to print usage when subcommand has not been provided should just call print(makeUsage()) and terminate the app.

@jodoll
Copy link

jodoll commented Aug 17, 2022

Just stumbled upon the same issue. Would be nice if there would be an option to enable this behavior or the option to call makeUsage. However, I worked around the issue by just adding -h to the arguments if the list is empty. Of course this only works if you don't want to use it on a subcommand and you know that 0 arguments is invalid.

    val arguments = "-h"
        .takeIf { args.isEmpty() }
        ?.let { args + it }
        ?: args

    parser.parse(arguments)

@lkb2k
Copy link

lkb2k commented Dec 2, 2022

Another vote for making printError or makeUsage public. I'd like to be able to output an error message and the usage statement if the app is just executed with no subcommands provided.

@lkb2k
Copy link

lkb2k commented Dec 2, 2022

Just stumbled upon the same issue. Would be nice if there would be an option to enable this behavior or the option to call makeUsage. However, I worked around the issue by just adding -h to the arguments if the list is empty. Of course this only works if you don't want to use it on a subcommand and you know that 0 arguments is invalid.

    val arguments = "-h"
        .takeIf { args.isEmpty() }
        ?.let { args + it }
        ?: args

    parser.parse(arguments)

Oh, nice idea! I tried it but unfortunately even this workaround isn't great since it will cause the app to return exit code 0 as if it was invoked with -h on purpose rather than returning an error.

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

5 participants