picocli

Can I define custom descriptions for Mixins for separate uses with picocli?


I have an algorithm with many similar @Options, for instance:

@Option(names = {"-if", "--input-file"}, required = true, description = "description")
public void setInputFilePath(String value) throws FileNotFoundException {
    checkInvalidPath(value); // throws FileNotFounException if path does not exist
    inputFile = value;
}

I want to make this option a @Mixin, but the problem here is that these options require very different files, so the description I need for the help command differs for each use. Is it possible to customize the description of a @Mixin option for each use?


Solution

  • You may be able to solve this with picocli's support for resource bundles.

    You can either have separate resource bundles for each command, or have a shared bundle by pointing each command to the same resource bundle.

    Within a shared single resource bundle you can prefix property names with the command name so that an option with the same key can have a different description in different commands.

    Example:

    #MySharedBundle.properties
    
    command1.input-file=description1
    command2.input-file=description2