Search code examples
apache-commons-cli

commons-cli dependent arguments


I use apache commons-cli for a command line tool. I have pairs of dependent arguments, e.g argument B makes sense only if argument A is present. That will have 2 benefits : automatic warning/error and a more usefull usage statment . Does commons-cli support it ?


Solution

  • It does not; you have to enforce such things manually. CLI has OptionGroups, but they are purely mutually exclusive options, not dependent options. See JavaDoc for Option, OptionBuilder (which I highly recommend using) and the previously mentioned OptionGroup.