1

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?

1 Answers1

1

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
Remko Popma
  • 35,130
  • 11
  • 92
  • 114
  • This did the trick! Is it also possible to set alternative default values this way? – Bitterblossom Apr 14 '22 at 14:04
  • For default values you can use a [default provider](https://picocli.info/#_default_provider). Picocli provides a built-in [properties default provider](https://picocli.info/#_propertiesdefaultprovider) that allows you to specify defaults for multiple commands in a single file. – Remko Popma Apr 14 '22 at 22:38