Skip to content

Commit

Permalink
Merge pull request #3550 from mulderbaba/PAYARA-3352-If-multiple-inva…
Browse files Browse the repository at this point in the history
…lid-options-are-specified-for-asadmin-only-first-is-reported

PAYARA-3352-If-multiple-invalid-options-are-specified-for-asadmin-only-first-is-reported
  • Loading branch information
arjantijms authored Jan 18, 2019
2 parents b2e472c + a5539a7 commit 8d0a8b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# only if the new code is made subject to such option by the copyright
# holder.
#
# Portions Copyright [2019] Payara Foundation and/or affiliates

CommandSuccessful=Command {0} executed successfully.
CommandSuccessfulWithWarnings=Command {0} completed with warnings.
Expand Down Expand Up @@ -202,6 +203,7 @@ DeprecatedSyntax=Deprecated syntax, instead use:
parser.noValueAllowed=Option may not have value: {0}
parser.illegalNo="--no" illegal with non-boolean option: {0}
parser.invalidOption=Invalid option: {0}
parser.invalidOptions=Invalid options: {0}
parser.nonbooleanNotAllowed=Non-boolean option: {0}, not allowed in argument: {1}
parser.missingValue=Missing value for option: {0}
parser.invalidFileEx=Invalid file for option: --{0}: {1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2018] Payara Foundation and/or affiliates
// Portions Copyright [2018-2019] Payara Foundation and/or affiliates

package com.sun.enterprise.admin.cli;

import java.io.*;
import java.util.*;

import com.sun.enterprise.util.StringUtils;
import org.glassfish.api.admin.*;
import org.glassfish.api.admin.CommandModel.ParamModel;
import com.sun.enterprise.admin.util.CommandModelData.ParamModelData;
Expand All @@ -56,7 +58,10 @@
public class Parser {
/** MultiMap of options and values from command-line */
private ParameterMap optionsMap = new ParameterMap();


/** Set of invalid options' names from command-line */
private Set<String> invalidOptions = new HashSet<>();

/** Array of operands from command-line */
private List<String> operands = new ArrayList<String>();

Expand Down Expand Up @@ -176,7 +181,7 @@ private void parseCommandLine(final String[] argv, final int start)
opt = lookupShortOption(arg.charAt(i));
if (opt == null) {
if (!ignoreUnknown) {
throw new CommandValidationException(strings.get("parser.invalidOption", Character.toString(arg.charAt(i))));
invalidOptions.add(arg);
}
// unknown option, skip all the rest
operands.add(arg);
Expand All @@ -202,7 +207,7 @@ private void parseCommandLine(final String[] argv, final int start)
// is it a known option?
if (opt == null) {
if (!ignoreUnknown){
throw new CommandValidationException(strings.get("parser.invalidOption", arg));
invalidOptions.add(arg);
}
// unknown option, skip it
operands.add(arg);
Expand Down Expand Up @@ -240,7 +245,16 @@ private void parseCommandLine(final String[] argv, final int start)
}
}
}
setOption(opt, value);
if (invalidOptions.isEmpty()) {
setOption(opt, value);
}
}

if (invalidOptions.size() == 1) {
throw new CommandValidationException(strings.get("parser.invalidOption", invalidOptions.iterator().next()));
}
else if (invalidOptions.size() > 1) {
throw new CommandValidationException(strings.get("parser.invalidOptions", StringUtils.cat(" ", invalidOptions.toArray(new String[0]))));
}
}

Expand Down

0 comments on commit 8d0a8b4

Please sign in to comment.