Search code examples
picocli

Picocli option list alignment problem in usage-help message


I am using a command using PicoCLI v4.0.0-alpha-3. No matter which options I try, the one that shows at the top (when the list of options is displayed in the CL) is always to the right of the other options. How can this be configured so that all options for a command are aligned at the same level?

@CommandLine.Command(name = "",
        description = "test",
        header = "%n@|green test|@",
        footer = {"",
                "@|cyan Press Ctrl-D to exit the CLI.|@",
                ""},
        version = "1.0.0",
        showDefaultValues = true,
        optionListHeading = "@|bold %nOptions|@:%n",
        subcommands = {
                Abc.class,
                Def.class
        })
public class Tester implements Callable<Integer> {  

    @Option(names = {"-v", "--verbose"}, description = "Verbose mode. Helpful for troubleshooting.")
    private boolean verboseMode;

    @Option(names = {"-a", "--autocomplete"}, description = "Generate sample autocomplete")
    private boolean autocomplete;

Display on CLI

Options:
      --v, --version   Show version info and exit.
  -a, --autocomplete   Generate sample autocomplete

The first option is always misaligned. I am trying to ensure that the first option is aligned at the same level as other options.


Solution

  • You may have found a bug. I will investigate.


    Update:

    Looking closer at the output:

    Options:
          --v, --version   Show ...
      -a, --autocomplete   Generate ...
    

    You can see that both the --v option and the --version option have two leading - hyphens. That’s why picocli considers both as “long options” and puts them in the column for long options.

    If you give the --v option a single leading hyphen so it becomes a POSIX-compliant short option -v, you should see it line up correctly.