【问题标题】:setting min , max and exact no. of arguments required for option using commons cli设置 min , max 和确切的编号。使用 commons cli 的选项所需的参数
【发布时间】:2014-06-15 05:35:16
【问题描述】:

我正在使用 Apache Commons cli。我使用 OptionBuilder 创建了不同的选项:

final Option name = OptionBuilder.withArgName().hasArgs().withDescription()
                     .withLongOpt()

我的问题是我想为选项设置固定数量的参数。如果用户传递的参数更少或更多,它应该抛出异常。

对于其他选项,我想设置允许的最小和最大参数数量。

我怎样才能做到这一点?

【问题讨论】:

    标签: java apache-commons-cli


    【解决方案1】:

    您可以使用Option.setArgs(int num) 设置所需参数的确切数量。

    无法设置最小值和最大值。也许您可以使用setArgs 设置最大值并手动检查最小值。或者,在 Jira 网站上提出功能请求:https://issues.apache.org/jira/browse/CLI

    【讨论】:

      猜你喜欢
      • 2018-01-21
      • 1970-01-01
      • 2013-10-22
      • 1970-01-01
      • 2016-05-11
      • 2012-07-27
      • 2015-03-05
      • 1970-01-01
      • 2021-11-27
      相关资源
      最近更新 更多