Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create an option name with hyphens in apache commons cli?

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?

like image 247
sonalir Avatar asked Feb 16 '16 02:02

sonalir


1 Answers

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).

like image 86
Thilo Avatar answered Nov 07 '22 02:11

Thilo