Skip to content

Commit 0c5f405

Browse files
author
Robert James Oxspring
committed
Parser no longer validates the CommandLine if the help option is found
Original patch supplied by Steve Alberty git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@190810 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8ee4b57 commit 0c5f405

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

  • src/java/org/apache/commons/cli2/commandline

src/java/org/apache/commons/cli2/commandline/Parser.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,32 @@ public class Parser {
5454
* command line tokens.
5555
*/
5656
public CommandLine parse(final String[] arguments) throws OptionException {
57-
57+
58+
// build a mutable list for the arguments
5859
final List argumentList = new LinkedList(Arrays.asList(arguments));
5960
final WriteableCommandLine commandLine =
6061
new WriteableCommandLineImpl(group, new ArrayList());
6162

6263
// pick up any defaults from the model
6364
group.defaults(commandLine);
64-
65+
66+
// process the options as far as possible
6567
final ListIterator iterator = argumentList.listIterator();
6668
while (group.canProcess(commandLine, iterator)) {
6769
group.process(commandLine, iterator);
6870
}
69-
71+
72+
// if there are more arguments we have a problem
7073
if (iterator.hasNext()) {
7174
final String arg = (String)iterator.next();
7275
throw new OptionException(group, "cli.error.unexpected", arg);
7376
}
74-
75-
group.validate(commandLine);
76-
77+
78+
// no need to validate if the help option is present
79+
if (!commandLine.hasOption(helpOption) && !commandLine.hasOption(helpTrigger)) {
80+
group.validate(commandLine);
81+
}
82+
7783
return commandLine;
7884
}
7985

0 commit comments

Comments
 (0)