[
https://issues.apache.org/jira/browse/CLI-179?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16764585#comment-16764585
]
Frank Greguska commented on CLI-179:
------------------------------------
I agree this should be part of the commons-cli package but here is a simple
function that determines if help should be printed or not (could do something
similar for version). Call this before parse() and if it returns true, print
the help and exit before parsing the args.
{code:java}
private static boolean printHelp(String[] args){
String longName = OPTIONS.getOption("help").getLongOpt();
String shortName = OPTIONS.getOption("help").getOpt();
return Arrays.stream(args).anyMatch(s ->
s.replace("-", "").equals(longName) ||
s.replace("-", "").equals(shortName)
);
}
{code}
> Needs "standalone" options that can be used even if required options are not
> set
> --------------------------------------------------------------------------------
>
> Key: CLI-179
> URL: https://issues.apache.org/jira/browse/CLI-179
> Project: Commons CLI
> Issue Type: Improvement
> Components: Parser
> Affects Versions: 1.2
> Reporter: Joël Royer
> Priority: Major
> Attachments: CLI-179.patch
>
>
> it is currently impossible to have options like "help" or "version" if we
> also have some required options. The parsing results in an error "Missing
> parameters".
> But for an "help" or "version" option, it would be usefull to display the
> wanted information, even if required options are not set.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)