Picocli: Problematic formatting: descriptions containing newlines

Created on 4 Aug 2018  路  11Comments  路  Source: remkop/picocli

When I create a command description, newlines work perfectly when directly triggered with _--help_:

image

However, when it is shown for a parent command on which --help was triggered and shown in the list under _Commands:_, it breaks the flow completely (I tried with _\n_ and _%n_):

image

See that Note 1, 2 and 3? Is there a solution for this?

bug

All 11 comments

Same as with #429:

Also, I couldn't find any documentation on how multiple descriptions are handled by picocli rather than a single one with newlines in it.
I discovered I can replace newlines by having multiple descriptions in the description array, but in the _Command:_ listing then, only the first description from the array is shown, which is not the behavior I'm looking for (I expected all descriptions to be rendered).

I've pushed a fix for this to master. Can you build the project and try it?

I was in a rush and did not have time to create a unit test yet. Can you provide one (or some code snippets that help me reproduce the original problem)? You can just paste some of the code you used to test in a comment here - would be very helpful!

Simple Java Mail salutes you; it works. I'll see what I can do about that junit test.

Providing the code I used for this is a little problematic. I'm translating from a Java builder API to an intermediate model which is then translated to a picocli command structure. I'll see if I can provide a simple demo.

This shows the bug with the current latest version in Maven, which is solved by the change you made:

private static void runTest() {
    CommandSpec rootCmd = createCmd("newlines", "Displays subcommands, one of which contains description newlines");

    rootCmd.addSubcommand("subA", createCmd("subA", "regular description for subA"));
    rootCmd.addSubcommand("subB", createCmd("subB", "very,\nspecial,\nChristopher Walken style,\ndescription."));
    rootCmd.addSubcommand("subC", createCmd("subC", "regular description for subC"));

    CommandLine.ParseResult pr = new CommandLine(rootCmd).parseArgs("--help");
    CommandLine.printHelpIfRequested(pr.asCommandLineList(), out, err, Ansi.AUTO);
}

private static CommandSpec createCmd(String name, String description) {
    CommandSpec cmd = CommandSpec.create()
            .name(name)
            .mixinStandardHelpOptions(true);
    cmd.usageMessage()
            .description(description);
    return cmd;
}

Speaking of which, is the current GitHub source stable? I tend to give my library users the freedom to upgrade maven dependencies in case some breaking bug or security issue is solved. That's why I prefer relying on maven releases...

Thanks for the test!

The master branch is continuously modified. I鈥檒l release a new version that includes this fix in the next few days.

FYI: picocli is on maven: https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22picocli%22

Yeah, was already using that. But since you advocate including the entire file in projects, I thought you might have a stable master or something (or an LTS branch).

Good point. I should point to a release tag.

On a side note, do you know of a terminal in Windows 10 that renders ANSI codes properly? @|bold ...|@ doesn't work at all and @|bold,italic ...|@ gives it a white background with black font.

Currently tried cmd, Powershell and ConEmu.

Have you tried Cygwin? That looks quite pretty and even shows italic.

picocli 3.5 has been released which includes the fix for this issue.

You may also like the interactive feature to read passwords from the console with echo disabled.

Was this page helpful?
0 / 5 - 0 ratings