ali haider
ali haider

Reputation: 20182

display options for subcommands using PicoCLI

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 

Upvotes: 2

Views: 1531

Answers (1)

Remko Popma
Remko Popma

Reputation: 36754

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.

Upvotes: 2

Related Questions