Search code examples
javacommand-linecommand-line-interfaceapache-commonsapache-commons-cli

Java commons-cli, options with list of possible values


How can I make an option accept only some specified values like in the following example:

$ java -jar Mumu.jar -a foo
OK
$ java -jar Mumu.jar -a bar
OK
$ java -jar Mumu.jar -a foobar
foobar is not a valid value for -a

Solution

  • Since commons-cli doesn't support that directly, the simplest solution is probably to check the value of an option when you get it.