Is there a way to print help message when user didn't provide subcommand ?
Following doesn't work because it runs callable that doesn't have implementation.
@Command(
name = "tool",
mixinStandardHelpOptions = true,
subcommands = [ListPlugins::class, RunJob::class, CommandLine.HelpCommand::class])
class Main : Callable<Int> {
override fun call(): Int {
// CommandLine.HelpCommand().run()
return 0
}
}
To rephrase the question: How to show help when the user didn’t specify a subcommand?
From picoli version 4.3, you can simply not implement
Callable
on the top-level command; this makes it mandatory for users to specify a subcommand. (This assumes that you useCommandLine.execute
to parse the command line and run the business logic.)If no subcommand is specified, a "Missing required subcommand" error message is displayed, followed by the usage help message.
See: https://picocli.info/#_required_subcommands for details.
Does that meet your requirements?