I am trying to set Option name with hyphens in it like "source-files" using the Apache Commons CLI java library.
Option option = new Option("source-files", true, "List of source files")
I get this error,
java.lang.IllegalArgumentException: opt contains illegal character value '-'
at org.apache.commons.cli.OptionValidator.validateOption(OptionValidator.java:73)
at org.apache.commons.cli.Option.<init>(Option.java:123)
at org.apache.commons.cli.Option.<init>(Option.java:105)
Which means I cannot use an option name with a hyphen in it, which is the standard with unix commands. I noticed that Commons CLI documentation mentions a hyphenated option name in one their examples. Am I missing something here?
You can only use -
in the "long name":
options.addOption("S", "source-files", true, "List of source files")
If you want to only have the long name, you may need to use OptionBuilder
(not sure).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With