Search code examples
javapicocli

Picocli: Require certain parameters


Is it possible with picocli to implement the following?

Valid:

  • -A (-B | -C)

  • -D (-B | -C) [(-B | -C) ...]

(-A / -D are not required)

Invalid:

  • -B without -A or -D

  • -C without -A or -D

  • -A with -B and -C

  • -D with -B and -C

  • -A without (-B | -C)

  • -D without (-B | -C)

Thanks!


Solution

  • It should be possible to use picocli's argument groups to get this:

    [(-A |-D) (-B | -C) [(-B | -C) ...]]
    

    ... by creating a mutually exclusive group for -A and -D, and another mutually exclusive group (with multiplicity 1..*) for -B and -C, and create a composite group of these two groups that are mutually dependent. Since -A and -D are not required, the multiplicity of this composite group would be 0..1.