我可以在apache commons cli中创建带连字符的选项名称吗?

时间:2022-05-09 17:07:29

I am trying to set Option name with hyphens in it like "source-files" using the Apache Commons CLI java library.

我正在尝试使用Apache Commons CLI java库在其中设置带有连字符的选项名称,如“source-files”。

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?

这意味着我不能使用带有连字符的选项名称,这是unix命令的标准。我注意到Commons CLI文档在他们的示例中提到了一个带连字符的选项名称。我在这里错过了什么吗?

1 个解决方案

#1


3  

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

如果您只想拥有长名称,则可能需要使用OptionBuilder(不确定)。

#1


3  

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

如果您只想拥有长名称,则可能需要使用OptionBuilder(不确定)。