commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Heuer <heue...@acm.org>
Subject Re: [CLI] Simple usage message
Date Wed, 02 Sep 2009 19:10:02 GMT
Jim Jagielski wrote:

> There are times when add in -h/--help and want to allow people
> to just go ahead and call the app with that option. The rub is, of
> course, if there are any required options, in addition to the usage
> message they also get a superfluous "Missing required" note as well...
>
> This is, imo at least, ugly. If the consensus is that this would be
> something nice to fix in the 1.x tree (not sure if still an issue in
> 2.x), I'll open a JIRA and start work.

There is a workaround if you have only one required option:

  Options options = ...;
  Option requiredOption = ...;
  requiredOption.setRequired(false);
  Option help = ...;
  help.setRequired(false);
  OptionGroup requiredOptions = new OptionGroup();
  requiredOptions.addOption(required);
  requiredOptions.addOption(help);
  requiredOptions.setRequired(true);
  options.addOptionGroup(requiredOptions);

but this doesn't work if you have more than one required option.

   michael


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message