kotlinx-cli
kotlinx-cli copied to clipboard
Show help if no subcommands provided
It would be nice to have an option to show the help of the subcommand if no options and no subcommands are specified.
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?
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
This is replated to subcommand with only possible subcommand, without arguments and options
But if subcommand can be executed without any options? It can have all options with default values.
But if
subcommandcan 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
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.
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)
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.
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-hto 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.