picocli icon indicating copy to clipboard operation
picocli copied to clipboard

subcommandsRepeatable = true vs HelpCommand

Open roxspring opened this issue 2 years ago • 3 comments

If I've understood correctly then it seems that @CommandLine(subcommandsRepeatable) breaks HelpCommand's ability to provide help for that command.

For example, given a tool with subcommandsRepeatable = true and a subcommand sub, then I'd expect tool help sub to provide the usage for the sub subcommand, but what I see is the usage for tool itself.

Is this expected to work already and I'm doing something wrong? Or does this seem like a bug?

(I'll aim to isolate an example together tomorrow, but thought it might be worth starting the conversation sooner...)

roxspring avatar Sep 28 '23 00:09 roxspring

That does look unexpected. Could well be a bug. Thank you for raising this!

remkop avatar Sep 28 '23 08:09 remkop

Opened #2126 demonstrating the problem in a unit test.

Any thoughts on the best route forwards? Options that I see:

  1. HelpCommand.commands parameter somehow gets marked as "greedy" so that it takes precedence over command parsing!?
  2. HelpCommand falls back to interrogating parent.getCommandSpec().subcommands() to find which subcommands need usage shown
    1. Presumably multiple subcommands could be found this way, but only one usage should be shown...
    2. Is there an obvious choice which subcommand's usage should be shown?
  3. Just strongly recommend using --help options rather than the help command.

roxspring avatar Sep 28 '23 15:09 roxspring

Added a potential fix to https://github.com/remkop/picocli/pull/2126 using a custom IParameterPreprocessor to implement the greedy approach (1). Feedback welcome!

roxspring avatar Oct 03 '23 08:10 roxspring