Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/main/java/org/apache/commons/cli/DefaultParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ private void handleToken(final String token) throws ParseException {
if (token != null) {
currentToken = token;
if (skipParsing) {
cmd.addArg(token);
addArg(token);
} else if ("--".equals(token)) {
skipParsing = true;
} else if (currentOption != null && currentOption.acceptsArg() && isArgument(token)) {
Expand All @@ -582,17 +582,28 @@ private void handleToken(final String token) throws ParseException {
* the remaining tokens are added as-is in the arguments of the command line.
*
* @param token the command line token to handle
* @throws ParseException if parsing should fail
*/
private void handleUnknownToken(final String token) throws ParseException {
protected void handleUnknownToken(final String token) throws ParseException {
if (token.startsWith("-") && token.length() > 1 && !stopAtNonOption) {
throw new UnrecognizedOptionException("Unrecognized option: " + token, token);
}
cmd.addArg(token);
addArg(token);
if (stopAtNonOption) {
skipParsing = true;
}
}

/**
* Adds token to command line {@link CommandLine#addArg(String)}.
*
* @param token the unrecognized option/argument.
* @since 1.10.0
*/
protected void addArg(final String token) {
cmd.addArg(token);
}

/**
* Tests if the token is a valid argument.
*
Expand Down