2

I am using PicoCLI v4.0.0-beta-1b. I am using different subcommands linked from a parent command. The parent command's optional parameters get displayed when I launch the CLI but not for the subcommands. The subcommands only appears underneath commands (but with no options). How does one go about to ensure that the options for subcommands appear in the CLI as well?

Options:
  -a, --autocomplete   Generate sample autocomplete
  -h, --help           Display this help message.
  -v, --verbose        Verbose mode. Helpful for troubleshooting.
  -V, --version        Show version info and exit.
Commands:
  abc
  def 
ali haider
  • 19,175
  • 17
  • 80
  • 149

1 Answers1

2

By default, picocli only shows an overview of a command's subcommands, and no details. This follows the conventions of other command suites like git. The idea is that end users can always get details for another subcommand by asking for help for that specific subcommand, like git commit --help, or git help commit.

While this is a useful default, if that's not what you want, picocli usage help is highly customizable.

The picocli usage message has the following sections:

  • header heading
  • header
  • synopsis heading
  • synopsis
  • description heading
  • description
  • positional parameter list heading
  • positional parameter list
  • option list heading
  • option list
  • command list heading
  • command list
  • exit code list heading (since 4.0)
  • exit code list (since 4.0)
  • footer heading
  • footer

Each section has its own IHelpSectionRenderer, and you can change the usage help by removing, reordering or replacing these help section renderers.

An example to get you started is here: https://github.com/remkop/picocli/blob/master/picocli-examples/src/main/java/picocli/examples/customhelp/ShowAll.java

The above example has a custom IHelpSectionRenderer for the command list, to show the full hierarchy of commands, subcommands, and sub-subcommands, etc. You may want to do something similar but show the options of the subcommands instead.

You will need to familiarize yourself with some details of the picocli Help API, like TextTable, Layout, IOptionRenderer, etc.

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
  • 1
    thank you - much appreciated. I will try out the recommended solution. In my case, the parent command does not do much (using with jline). – ali haider Jun 10 '19 at 23:15
  • thanks...I would have expected the opposite for the default or an option at the top level command to show all subcommand params/groups. – kenyee Mar 27 '23 at 13:29